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


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
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to