[cfe-commits] r167703 - /cfe/trunk/lib/AST/Decl.cpp

Rafael Espindola rafael.espindola at gmail.com
Sun Nov 11 20:10:23 PST 2012


Author: rafael
Date: Sun Nov 11 22:10:23 2012
New Revision: 167703

URL: http://llvm.org/viewvc/llvm-project?rev=167703&view=rev
Log:
In Sema::MergeVarDecl we handle merging of storage classes and visibility
attributes. In cases where the merged declaration is fully equivalent to the
two original ones, some of the code was getLVForDecl was duplicated.

Cases that are still handled in getLVForDecl are things like

__private_extern__ int N;
int N;

For which we cannot produce a single merged decl with all the information.

Modified:
    cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=167703&r1=167702&r2=167703&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sun Nov 11 22:10:23 2012
@@ -341,25 +341,9 @@
     if (Var->getStorageClass() == SC_PrivateExtern)
       LV.mergeVisibility(HiddenVisibility, true);
 
-    if (!Context.getLangOpts().CPlusPlus &&
-        (Var->getStorageClass() == SC_Extern ||
-         Var->getStorageClass() == SC_PrivateExtern)) {
-
-      // C99 6.2.2p4:
-      //   For an identifier declared with the storage-class specifier
-      //   extern in a scope in which a prior declaration of that
-      //   identifier is visible, if the prior declaration specifies
-      //   internal or external linkage, the linkage of the identifier
-      //   at the later declaration is the same as the linkage
-      //   specified at the prior declaration. If no prior declaration
-      //   is visible, or if the prior declaration specifies no
-      //   linkage, then the identifier has external linkage.
-      if (const VarDecl *PrevVar = Var->getPreviousDecl()) {
-        LinkageInfo PrevLV = getLVForDecl(PrevVar, OnlyTemplate);
-        if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
-        LV.mergeVisibility(PrevLV);
-      }
-    }
+    // Note that Sema::MergeVarDecl already takes care of implementing
+    // C99 6.2.2p4 and propagating the visibility attribute, so we don't have
+    // to do it here.
 
   //     - a function, unless it has internal linkage; or
   } else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
@@ -841,13 +825,10 @@
           if (llvm::Optional<Visibility> Vis = Var->getExplicitVisibility())
             LV.mergeVisibility(*Vis, true);
         }
-        
-        if (const VarDecl *Prev = Var->getPreviousDecl()) {
-          LinkageInfo PrevLV = getLVForDecl(Prev, OnlyTemplate);
-          if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
-          LV.mergeVisibility(PrevLV);
-        }
 
+        // Note that Sema::MergeVarDecl already takes care of implementing
+        // C99 6.2.2p4 and propagating the visibility attribute, so we don't
+        // have to do it here.
         return LV;
       }
   }





More information about the cfe-commits mailing list