[cfe-commits] r170406 - in /cfe/trunk: lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp test/Index/linkage.c

Rafael Espindola rafael.espindola at gmail.com
Mon Dec 17 20:18:55 PST 2012


Author: rafael
Date: Mon Dec 17 22:18:55 2012
New Revision: 170406

URL: http://llvm.org/viewvc/llvm-project?rev=170406&view=rev
Log:
Merge storage classes even when contexts don't match.

This fixes the storage class of extern decls that are merged with file level
statics. The patch also fixes the linkage computation so that they are
considered internal.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Index/linkage.c

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=170406&r1=170405&r2=170406&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Dec 17 22:18:55 2012
@@ -786,12 +786,16 @@
     }
 
     if (const VarDecl *Var = dyn_cast<VarDecl>(D))
-      if (Var->getStorageClass() == SC_Extern ||
-          Var->getStorageClass() == SC_PrivateExtern) {
+      if (Var->getStorageClassAsWritten() == SC_Extern ||
+          Var->getStorageClassAsWritten() == SC_PrivateExtern) {
         if (Var->isInAnonymousNamespace() &&
             !Var->getDeclContext()->isExternCContext())
           return LinkageInfo::uniqueExternal();
 
+        // This is an "extern int foo;" which got merged with a file static.
+        if (Var->getStorageClass() == SC_Static)
+          return LinkageInfo::internal();
+
         LinkageInfo LV;
         if (Var->getStorageClass() == SC_PrivateExtern)
           LV.mergeVisibility(HiddenVisibility, true);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170406&r1=170405&r2=170406&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 17 22:18:55 2012
@@ -2616,8 +2616,7 @@
   // specified at the prior declaration.
   // FIXME. revisit this code.
   if (New->hasExternalStorage() &&
-      Old->getLinkage() == InternalLinkage &&
-      New->getDeclContext() == Old->getDeclContext())
+      Old->getLinkage() == InternalLinkage)
     New->setStorageClass(Old->getStorageClass());
 
   // Merge "used" flag.

Modified: cfe/trunk/test/Index/linkage.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/linkage.c?rev=170406&r1=170405&r2=170406&view=diff
==============================================================================
--- cfe/trunk/test/Index/linkage.c (original)
+++ cfe/trunk/test/Index/linkage.c Mon Dec 17 22:18:55 2012
@@ -13,6 +13,12 @@
 
 void ena(int (*dio)(int tria));
 
+static int test2;
+void f16(void) {
+  extern int test2;
+}
+
+
 // CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External
 // CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External
 // CHECK: VarDecl=x:4:5linkage=External
@@ -28,3 +34,5 @@
 // CHECK: FunctionDecl=ena:14:6linkage=External
 // CHECK: ParmDecl=dio:14:16 (Definition)linkage=NoLinkage
 // CHECK: ParmDecl=tria:14:25 (Definition)linkage=NoLinkage
+// CHECK: VarDecl=test2{{.*}}linkage=Internal
+// CHECK: VarDecl=test2{{.*}}linkage=Internal





More information about the cfe-commits mailing list