]> granicus.if.org Git - clang/commitdiff
[modules] Allow "redefinition" of typedef of anon tag from unimported submodule
authorBen Langmuir <blangmuir@apple.com>
Sat, 14 Nov 2015 03:26:14 +0000 (03:26 +0000)
committerBen Langmuir <blangmuir@apple.com>
Sat, 14 Nov 2015 03:26:14 +0000 (03:26 +0000)
r233345 started being stricter about typedef names for linkage purposes
in non-visible modules, but broke languages without the ODR.

rdar://23527954

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253123 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp
test/Index/usrs.m
test/Modules/Inputs/module.map
test/Modules/Inputs/typedef-tag-hidden.h [new file with mode: 0644]
test/Modules/Inputs/typedef-tag.h [new file with mode: 0644]
test/Modules/typedef-tag-not-visible.m [new file with mode: 0644]

index 3f6941ab72d988b4dd7338ce600a33967d67701b..edbbc6a8c4f5b94329317e2afb7c024c8745bddc 100644 (file)
@@ -1256,7 +1256,8 @@ static LinkageInfo computeLVForDecl(const NamedDecl *D,
     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;
index e7c10d18a669030a0f379951b923f3e8f53c34a7..d051c4318dd23e4eb72affc595a988a77578456c 100644 (file)
@@ -1829,7 +1829,8 @@ static void filterNonConflictingPreviousTypedefDecls(Sema &S,
 
       // 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;
     }
index aa0c4a04fc7e8f1216bea25caee0cff0a94153c7..fc3fbc9105789f6f9dc0a680a75f4d1c11eb19f9 100644 (file)
@@ -119,7 +119,7 @@ int test_multi_declaration(void) {
 // CHECK: usrs.m c:@SA@MyStruct Extent=[15:9 - 18:2]
 // CHECK: usrs.m c:@SA@MyStruct@FI@wa Extent=[16:3 - 16:9]
 // CHECK: usrs.m c:@SA@MyStruct@FI@moo Extent=[17:3 - 17:10]
-// CHECK: usrs.m c:@T@MyStruct Extent=[15:1 - 18:11]
+// CHECK: usrs.m c:usrs.m@T@MyStruct Extent=[15:1 - 18:11]
 // CHECK: usrs.m c:@E@Pizza Extent=[20:1 - 23:2]
 // CHECK: usrs.m c:@E@Pizza@CHEESE Extent=[21:3 - 21:9]
 // CHECK: usrs.m c:@E@Pizza@MUSHROOMS Extent=[22:3 - 22:12]
index d195e2f0980f642eb8d27d79b604bce8de944dd5..226d45fdf44b4b744a5b2f9891df8bb3ce4aaf39 100644 (file)
@@ -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"
+  }
+}
diff --git a/test/Modules/Inputs/typedef-tag-hidden.h b/test/Modules/Inputs/typedef-tag-hidden.h
new file mode 100644 (file)
index 0000000..eb59d69
--- /dev/null
@@ -0,0 +1 @@
+typedef struct { int x; } TypedefStructHidden_t;
diff --git a/test/Modules/Inputs/typedef-tag.h b/test/Modules/Inputs/typedef-tag.h
new file mode 100644 (file)
index 0000000..77dff95
--- /dev/null
@@ -0,0 +1 @@
+typedef struct { int x; } TypedefStructVisible_t;
diff --git a/test/Modules/typedef-tag-not-visible.m b/test/Modules/typedef-tag-not-visible.m
new file mode 100644 (file)
index 0000000..e1a6406
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify
+
+@import TypedefTag;
+
+typedef struct { int x; } TypedefStructHidden_t;
+typedef struct { int x; } TypedefStructVisible_t; // expected-error{{typedef redefinition}}
+// expected-note@typedef-tag.h:1 {{here}}