[Lldb-commits] [PATCH] D18976: Handle lookup of names identifying both a variable and a type

Ulrich Weigand via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 11 11:26:53 PDT 2016


uweigand created this revision.
uweigand added a reviewer: spyffe.
uweigand added a subscriber: lldb-commits.

In C++ code, a variable can have the same name as a type, e.g. like

int C;
struct C {
  static int a;
};

When evaluating an expression like "C::a" by the LLDB parser, clang
will call back into the external source asking for decls for the
identifier "C".  Currently, LLDB will only return the decl for the
variable C.  This in turn will cause clang to fail with an error.

(This happens for me with the lang/cpp/scope/TestCppScope.py test
case, due to a static variable C in one of the libm.so objects.)

Instead, it seems clang expects the external data source to return
*both* the variable and the type decl.  It will then choose the
appropriate one to use based on its current parsing context.

This patch changes ClangExpressionDeclMap::FindExternalVisibleDecls
to always call ClangASTSource::FindExternalVisibleDecls to possibly
identify types, even if we already found a variable of that name.


http://reviews.llvm.org/D18976

Files:
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -866,8 +866,11 @@
                                  current_id);
     }
 
-    if (!context.m_found.variable)
-        ClangASTSource::FindExternalVisibleDecls(context);
+    // Always call into ClangASTSource::FindExternalVisibleDecls, even if we already found
+    // some decls above.  It might be that Clang is looking for a type, but we have found
+    // a variable of the same name instead.  Let ClangASTSource add the type to the result
+    // list as well; Clang will filter out the decl it is actually interested in.
+    ClangASTSource::FindExternalVisibleDecls(context);
 }
 
 void


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18976.53291.patch
Type: text/x-patch
Size: 876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160411/10ede2d2/attachment.bin>


More information about the lldb-commits mailing list