r177721 - Fix DeclRefExpr::getFoundDecl() for usages by reference.

Daniel Jasper djasper at google.com
Fri Mar 22 03:01:36 PDT 2013


Author: djasper
Date: Fri Mar 22 05:01:35 2013
New Revision: 177721

URL: http://llvm.org/viewvc/llvm-project?rev=177721&view=rev
Log:
Fix DeclRefExpr::getFoundDecl() for usages by reference.

Added:
    cfe/trunk/test/Misc/ast-dump-stmt.cpp
Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=177721&r1=177720&r2=177721&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Mar 22 05:01:35 2013
@@ -3023,7 +3023,8 @@ public:
   ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
                               ExprValueKind VK,
                               const DeclarationNameInfo &NameInfo,
-                              const CXXScopeSpec *SS = 0);
+                              const CXXScopeSpec *SS = 0,
+                              NamedDecl *FoundD = 0);
   ExprResult
   BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
                                            SourceLocation nameLoc,
@@ -3056,7 +3057,7 @@ public:
                                       bool NeedsADL);
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
                                       const DeclarationNameInfo &NameInfo,
-                                      NamedDecl *D);
+                                      NamedDecl *D, NamedDecl *FoundD = 0);
 
   ExprResult BuildLiteralOperatorCall(LookupResult &R,
                                       DeclarationNameInfo &SuffixInfo,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=177721&r1=177720&r2=177721&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 22 05:01:35 2013
@@ -1431,7 +1431,7 @@ Sema::BuildDeclRefExpr(ValueDecl *D, Qua
 ExprResult
 Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
                        const DeclarationNameInfo &NameInfo,
-                       const CXXScopeSpec *SS) {
+                       const CXXScopeSpec *SS, NamedDecl *FoundD) {
   if (getLangOpts().CUDA)
     if (const FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext))
       if (const FunctionDecl *Callee = dyn_cast<FunctionDecl>(D)) {
@@ -1455,7 +1455,7 @@ Sema::BuildDeclRefExpr(ValueDecl *D, Qua
                                               : NestedNameSpecifierLoc(),
                                        SourceLocation(),
                                        D, refersToEnclosingScope,
-                                       NameInfo, Ty, VK);
+                                       NameInfo, Ty, VK, FoundD);
 
   MarkDeclRefReferenced(E);
 
@@ -2360,8 +2360,8 @@ Sema::BuildDeclarationNameExpr(const CXX
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
   if (!NeedsADL && R.isSingleResult() && !R.getAsSingle<FunctionTemplateDecl>())
-    return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(),
-                                    R.getFoundDecl());
+    return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), R.getFoundDecl(),
+                                    R.getRepresentativeDecl());
 
   // We only need to check the declaration if there's exactly one
   // result, because in the overloaded case the results can only be
@@ -2389,7 +2389,7 @@ Sema::BuildDeclarationNameExpr(const CXX
 ExprResult
 Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
                                const DeclarationNameInfo &NameInfo,
-                               NamedDecl *D) {
+                               NamedDecl *D, NamedDecl *FoundD) {
   assert(D && "Cannot refer to a NULL declaration");
   assert(!isa<FunctionTemplateDecl>(D) &&
          "Cannot refer unambiguously to a function template");
@@ -2585,7 +2585,7 @@ Sema::BuildDeclarationNameExpr(const CXX
       break;
     }
 
-    return BuildDeclRefExpr(VD, type, valueKind, NameInfo, &SS);
+    return BuildDeclRefExpr(VD, type, valueKind, NameInfo, &SS, FoundD);
   }
 }
 

Added: cfe/trunk/test/Misc/ast-dump-stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-stmt.cpp?rev=177721&view=auto
==============================================================================
--- cfe/trunk/test/Misc/ast-dump-stmt.cpp (added)
+++ cfe/trunk/test/Misc/ast-dump-stmt.cpp Fri Mar 22 05:01:35 2013
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter Test %s | FileCheck -strict-whitespace %s
+
+namespace n {
+void function() {}
+int Variable;
+}
+using n::function;
+using n::Variable;
+void TestFunction() {
+  void (*f)() = &function;
+// CHECK:       DeclRefExpr{{.*}} (UsingShadow{{.*}}function
+  Variable = 4;
+// CHECK:       DeclRefExpr{{.*}} (UsingShadow{{.*}}Variable
+}





More information about the cfe-commits mailing list