r306917 - Change enumerator default linkage type for C

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 30 17:06:27 PDT 2017


Author: bruno
Date: Fri Jun 30 17:06:27 2017
New Revision: 306917

URL: http://llvm.org/viewvc/llvm-project?rev=306917&view=rev
Log:
Change enumerator default linkage type for C

Redeclaration lookup should never find hidden enumerators in C, because
they do not have linkage (C11 6.2.2/6)

The linkage of an enumerator should be VisibleNoLinkage, and
isHiddenDeclarationVisible should be checking hasExternalFormalLinkage.

This is was reviewed as part of D31778, but splitted into a different
commit for clarity.

rdar://problem/31909368

Modified:
    cfe/trunk/include/clang/Basic/Visibility.h
    cfe/trunk/include/clang/Sema/Lookup.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/Index/linkage.c

Modified: cfe/trunk/include/clang/Basic/Visibility.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Visibility.h?rev=306917&r1=306916&r2=306917&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Visibility.h (original)
+++ cfe/trunk/include/clang/Basic/Visibility.h Fri Jun 30 17:06:27 2017
@@ -75,6 +75,9 @@ public:
   static LinkageInfo none() {
     return LinkageInfo(NoLinkage, DefaultVisibility, false);
   }
+  static LinkageInfo visible_none() {
+    return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false);
+  }
 
   Linkage getLinkage() const { return (Linkage)linkage_; }
   Visibility getVisibility() const { return (Visibility)visibility_; }

Modified: cfe/trunk/include/clang/Sema/Lookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=306917&r1=306916&r2=306917&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Lookup.h (original)
+++ cfe/trunk/include/clang/Sema/Lookup.h Fri Jun 30 17:06:27 2017
@@ -275,7 +275,7 @@ public:
   /// declarations, such as those in modules that have not yet been imported.
   bool isHiddenDeclarationVisible(NamedDecl *ND) const {
     return AllowHidden ||
-           (isForRedeclaration() && ND->isExternallyVisible());
+           (isForRedeclaration() && ND->hasExternalFormalLinkage());
   }
 
   /// Sets whether tag declarations should be hidden by non-tag

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=306917&r1=306916&r2=306917&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Jun 30 17:06:27 2017
@@ -1251,7 +1251,9 @@ static LinkageInfo computeLVForDecl(cons
 
     case Decl::EnumConstant:
       // C++ [basic.link]p4: an enumerator has the linkage of its enumeration.
-      return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
+      if (D->getASTContext().getLangOpts().CPlusPlus)
+        return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
+      return LinkageInfo::visible_none();
 
     case Decl::Typedef:
     case Decl::TypeAlias:

Modified: cfe/trunk/test/Index/linkage.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/linkage.c?rev=306917&r1=306916&r2=306917&view=diff
==============================================================================
--- cfe/trunk/test/Index/linkage.c (original)
+++ cfe/trunk/test/Index/linkage.c Fri Jun 30 17:06:27 2017
@@ -20,7 +20,7 @@ void f16(void) {
 
 
 // CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External
-// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External
+// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=NoLinkage
 // CHECK: VarDecl=x:4:5linkage=External
 // CHECK: FunctionDecl=foo:5:6linkage=External
 // CHECK: VarDecl=w:6:12linkage=Internal




More information about the cfe-commits mailing list