r253123 - [modules] Allow "redefinition" of typedef of anon tag from unimported submodule

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 19:26:14 PST 2015


Author: benlangmuir
Date: Fri Nov 13 21:26:14 2015
New Revision: 253123

URL: http://llvm.org/viewvc/llvm-project?rev=253123&view=rev
Log:
[modules] Allow "redefinition" of typedef of anon tag from unimported submodule

r233345 started being stricter about typedef names for linkage purposes
in non-visible modules, but broke languages without the ODR.

rdar://23527954

Added:
    cfe/trunk/test/Modules/Inputs/typedef-tag-hidden.h
    cfe/trunk/test/Modules/Inputs/typedef-tag.h
    cfe/trunk/test/Modules/typedef-tag-not-visible.m
Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Index/usrs.m
    cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=253123&r1=253122&r2=253123&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Nov 13 21:26:14 2015
@@ -1256,7 +1256,8 @@ static LinkageInfo computeLVForDecl(cons
     case Decl::TypeAlias:
       // A typedef declaration has linkage if it gives a type a name for
       // linkage purposes.
-      if (!cast<TypedefNameDecl>(D)
+      if (!D->getASTContext().getLangOpts().CPlusPlus ||
+          !cast<TypedefNameDecl>(D)
                ->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
         return LinkageInfo::none();
       break;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=253123&r1=253122&r2=253123&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov 13 21:26:14 2015
@@ -1829,7 +1829,8 @@ static void filterNonConflictingPrevious
 
       // If both declarations give a tag declaration a typedef name for linkage
       // purposes, then they declare the same entity.
-      if (OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) &&
+      if (S.getLangOpts().CPlusPlus &&
+          OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) &&
           Decl->getAnonDeclWithTypedefName())
         continue;
     }

Modified: cfe/trunk/test/Index/usrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.m?rev=253123&r1=253122&r2=253123&view=diff
==============================================================================
--- cfe/trunk/test/Index/usrs.m (original)
+++ cfe/trunk/test/Index/usrs.m Fri Nov 13 21:26:14 2015
@@ -119,7 +119,7 @@ int test_multi_declaration(void) {
 // CHECK: usrs.m c:@SA at MyStruct Extent=[15:9 - 18:2]
 // CHECK: usrs.m c:@SA at MyStruct@FI at wa Extent=[16:3 - 16:9]
 // CHECK: usrs.m c:@SA at MyStruct@FI at moo Extent=[17:3 - 17:10]
-// CHECK: usrs.m c:@T at MyStruct Extent=[15:1 - 18:11]
+// CHECK: usrs.m c:usrs.m at T@MyStruct Extent=[15:1 - 18:11]
 // CHECK: usrs.m c:@E at Pizza Extent=[20:1 - 23:2]
 // CHECK: usrs.m c:@E at Pizza@CHEESE Extent=[21:3 - 21:9]
 // CHECK: usrs.m c:@E at Pizza@MUSHROOMS Extent=[22:3 - 22:12]

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=253123&r1=253122&r2=253123&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Fri Nov 13 21:26:14 2015
@@ -379,3 +379,10 @@ module DebugSubmodules {
 module ExtensionTestA {
   header "ExtensionTestA.h"
 }
+
+module TypedefTag {
+  header "typedef-tag.h"
+  explicit module Hidden {
+    header "typedef-tag-hidden.h"
+  }
+}

Added: cfe/trunk/test/Modules/Inputs/typedef-tag-hidden.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/typedef-tag-hidden.h?rev=253123&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/typedef-tag-hidden.h (added)
+++ cfe/trunk/test/Modules/Inputs/typedef-tag-hidden.h Fri Nov 13 21:26:14 2015
@@ -0,0 +1 @@
+typedef struct { int x; } TypedefStructHidden_t;

Added: cfe/trunk/test/Modules/Inputs/typedef-tag.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/typedef-tag.h?rev=253123&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/typedef-tag.h (added)
+++ cfe/trunk/test/Modules/Inputs/typedef-tag.h Fri Nov 13 21:26:14 2015
@@ -0,0 +1 @@
+typedef struct { int x; } TypedefStructVisible_t;

Added: cfe/trunk/test/Modules/typedef-tag-not-visible.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/typedef-tag-not-visible.m?rev=253123&view=auto
==============================================================================
--- cfe/trunk/test/Modules/typedef-tag-not-visible.m (added)
+++ cfe/trunk/test/Modules/typedef-tag-not-visible.m Fri Nov 13 21:26:14 2015
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify
+
+ at import TypedefTag;
+
+typedef struct { int x; } TypedefStructHidden_t;
+typedef struct { int x; } TypedefStructVisible_t; // expected-error{{typedef redefinition}}
+// expected-note at typedef-tag.h:1 {{here}}




More information about the cfe-commits mailing list