]> granicus.if.org Git - clang/commitdiff
[modules] If we load two declarations with typedef names for linkage purposes
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 22 Jan 2015 02:21:23 +0000 (02:21 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 22 Jan 2015 02:21:23 +0000 (02:21 +0000)
on top of a local declaration of the same entity, we still need to remember
that we loaded the first one or we may fail to merge the second one properly.

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

lib/Serialization/ASTReaderDecl.cpp
test/Modules/Inputs/merge-name-for-linkage/a.h [new file with mode: 0644]
test/Modules/Inputs/merge-name-for-linkage/b.h [new file with mode: 0644]
test/Modules/Inputs/merge-name-for-linkage/module.modulemap [new file with mode: 0644]
test/Modules/merge-name-for-linkage.cc [new file with mode: 0644]

index 8c03b0b8b27fab1b46330355fb24ebb822851c49..b82f987210fca94f7053f17fc774b4229b6a0314 100644 (file)
@@ -2554,15 +2554,21 @@ static DeclContext *getPrimaryContextForMerging(DeclContext *DC) {
 }
 
 ASTDeclReader::FindExistingResult::~FindExistingResult() {
+  // Record that we had a typedef name for linkage whether or not we merge
+  // with that declaration.
+  if (TypedefNameForLinkage) {
+    DeclContext *DC = New->getDeclContext()->getRedeclContext();
+    Reader.ImportedTypedefNamesForLinkage.insert(
+        std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
+    return;
+  }
+
   if (!AddResult || Existing)
     return;
 
   DeclarationName Name = New->getDeclName();
   DeclContext *DC = New->getDeclContext()->getRedeclContext();
-  if (TypedefNameForLinkage) {
-    Reader.ImportedTypedefNamesForLinkage.insert(
-        std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
-  } else if (!Name) {
+  if (!Name) {
     assert(needsAnonymousDeclarationNumber(New));
     setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
                                AnonymousDeclNumber, New);
diff --git a/test/Modules/Inputs/merge-name-for-linkage/a.h b/test/Modules/Inputs/merge-name-for-linkage/a.h
new file mode 100644 (file)
index 0000000..82f2fdd
--- /dev/null
@@ -0,0 +1 @@
+typedef union {} pthread_mutex_t;
diff --git a/test/Modules/Inputs/merge-name-for-linkage/b.h b/test/Modules/Inputs/merge-name-for-linkage/b.h
new file mode 100644 (file)
index 0000000..82f2fdd
--- /dev/null
@@ -0,0 +1 @@
+typedef union {} pthread_mutex_t;
diff --git a/test/Modules/Inputs/merge-name-for-linkage/module.modulemap b/test/Modules/Inputs/merge-name-for-linkage/module.modulemap
new file mode 100644 (file)
index 0000000..61578a1
--- /dev/null
@@ -0,0 +1,2 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
diff --git a/test/Modules/merge-name-for-linkage.cc b/test/Modules/merge-name-for-linkage.cc
new file mode 100644 (file)
index 0000000..1700b61
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-name-for-linkage -verify %s
+// expected-no-diagnostics
+typedef union {} pthread_mutex_t;
+#include "a.h"
+pthread_mutex_t x;
+#include "b.h"
+pthread_mutex_t y;