[Bug 31704] New: SBModule::FindFirstType does not find a second namespaced typedef with the same name

Bug ID 31704
Summary SBModule::FindFirstType does not find a second namespaced typedef with the same name
Product lldb
Version unspecified
Hardware Macintosh
OS MacOS X
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter alexandru.croitor@qt.io
CC llvm-bugs@lists.llvm.org
Classification Unclassified

Created attachment 17871 [details]
Example code which shows the issue regarding FindFirstType

SBModule::FindFirstType has an issue with finding namespaced typedefs.
Consider the code:

class Foo {
public:
    typedef bool MyType;
};

class Bar {
public:
    typedef int MyType;
};

int main(int argc, char* argv[]) {
    Foo::MyType foo;
    Bar::MyType bar;
    (void) foo;
    (void) bar;
    return 0;
}

Compile with clang++ -O0 -g ./main.cpp
Run with lldb ./a.out and go into python script mode

>>> lldb.target.FindTypes("MyType").GetSize()
2

>>> print lldb.target.FindFirstType("MyType")
typedef Foo::MyType

>>> print lldb.target.FindFirstType("Foo::MyType")
typedef Foo::MyType

>>> print lldb.target.FindFirstType("Bar::MyType")

As you can see, trying to find Bar::MyType fails, but if I iterate over
FindTypes result, I can find both.

(lldb) version
lldb-360.99.0
  clang revision a41b64721d4be78870711cbb7b5af156a9e1f4ad
  llvm revision 3c45ea423a9e3d27eaf77af0639a73e0c56d9a35

The issue seems to be inside lldb::TypeSP Module::FindFirstType(const
SymbolContext &sc, const ConstString &name, bool exact_match)
which passes "1" as the max_matches argument, and this gets propagated in a
wrong way inside the implementation, where essentially a list of the two types
is found, and the second type is not checked because the first type didn't
match.