]> granicus.if.org Git - clang/commitdiff
[Modules] Fix regression when an elaborated-type-specifier mentions a hidden tag
authorBen Langmuir <blangmuir@apple.com>
Thu, 10 Dec 2015 17:28:51 +0000 (17:28 +0000)
committerBen Langmuir <blangmuir@apple.com>
Thu, 10 Dec 2015 17:28:51 +0000 (17:28 +0000)
This makes non-C++ languages find the same decl as C++ does to
workaround a regression introduced in r252960.

rdar://problem/23784203

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

lib/Sema/SemaDecl.cpp
test/Modules/Inputs/elaborated-type-structs.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/elaborated-type-specifier-from-hidden-module.m [new file with mode: 0644]

index af5fdc95c9091df9c538222041aae6ce516bfe60..1d8f9b7d203cbaa758b76bce30aa4cf9978b3fc0 100644 (file)
@@ -12121,10 +12121,12 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
 
     // In C++, we need to do a redeclaration lookup to properly
     // diagnose some problems.
-    if (getLangOpts().CPlusPlus) {
-      Previous.setRedeclarationKind(ForRedeclaration);
-      LookupQualifiedName(Previous, SearchDC);
-    }
+    // FIXME: this lookup is also used (with and without C++) to find a hidden
+    // declaration so that we don't get ambiguity errors when using a type
+    // declared by an elaborated-type-specifier.  In C that is not correct and
+    // we should instead merge compatible types found by lookup.
+    Previous.setRedeclarationKind(ForRedeclaration);
+    LookupQualifiedName(Previous, SearchDC);
   }
 
   // If we have a known previous declaration to use, then use it.
diff --git a/test/Modules/Inputs/elaborated-type-structs.h b/test/Modules/Inputs/elaborated-type-structs.h
new file mode 100644 (file)
index 0000000..da39409
--- /dev/null
@@ -0,0 +1,3 @@
+struct S1;
+struct S2 { int x; };
+struct S3 { int x; };
index 226d45fdf44b4b744a5b2f9891df8bb3ce4aaf39..632517dd363fbe80a0b9c4d62c1aa2e2a2eada53 100644 (file)
@@ -386,3 +386,10 @@ module TypedefTag {
     header "typedef-tag-hidden.h"
   }
 }
+
+module ElaboratedTypeStructs {
+  module Empty {}
+  module Structs {
+    header "elaborated-type-structs.h"
+  }
+}
diff --git a/test/Modules/elaborated-type-specifier-from-hidden-module.m b/test/Modules/elaborated-type-specifier-from-hidden-module.m
new file mode 100644 (file)
index 0000000..0ca1c24
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify
+
+@import ElaboratedTypeStructs.Empty; // The structs are now hidden.
+struct S1 *x;
+struct S2 *y;
+// FIXME: compatible definition should not be an error.
+struct S2 { int x; }; // expected-error {{redefinition}}
+struct S3 *z;
+// Incompatible definition.
+struct S3 { float y; }; // expected-error {{redefinition}}
+// expected-note@elaborated-type-structs.h:* 2 {{previous definition is here}}
+
+@import ElaboratedTypeStructs.Structs;
+
+void useS1(struct S1 *x);
+void useS2(struct S2 *x);
+void useS2(struct S2 *x);