]> granicus.if.org Git - clang/commitdiff
[modules] When reading / writing a typedef that is a name for linkage for
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 26 Jan 2017 22:39:55 +0000 (22:39 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 26 Jan 2017 22:39:55 +0000 (22:39 +0000)
another declaration, ensure we actually serialize / deserialize that
declaration.

Before this patch, if another copy of the typedef were merged with the parsed
version, we would emit type information referring to the merged version and
consequently emit nothing about the parsed anonymous struct. This resulted in
us losing information, particularly the visible merged module set for the
parsed definition. Force that information to be emitted and to be loaded when
the typedef is used.

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

lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Modules/Inputs/merge-name-for-linkage/b.h
test/Modules/Inputs/merge-name-for-linkage/module.modulemap
test/Modules/merge-name-for-linkage.cpp

index 4a7e24c007a46bf35650bbaf0919e67c539d46f4..afda1a83c2aac5aa420a023409a1bac265ded1b4 100644 (file)
@@ -592,6 +592,11 @@ ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
     TD->setModedTypeSourceInfo(TInfo, modedT);
   } else
     TD->setTypeSourceInfo(TInfo);
+  // Read and discard the declaration for which this is a typedef name for
+  // linkage, if it exists. We cannot rely on our type to pull in this decl,
+  // because it might have been merged with a type from another module and
+  // thus might not refer to our version of the declaration.
+  ReadDecl();
   return Redecl;
 }
 
index d8466e9cbf3baf217ef881c0ba9264321dc7b752..292861755bace8a945ea3647aa9818464ede6658 100644 (file)
@@ -368,6 +368,7 @@ void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
   Record.push_back(D->isModed());
   if (D->isModed())
     Record.AddTypeRef(D->getUnderlyingType());
+  Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
 }
 
 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
index 82f2fdd83e3116acb602e59040039d68fc7718f6..5593e411713994135a9f7292cd26e29870db77ce 100644 (file)
@@ -1 +1,5 @@
 typedef union {} pthread_mutex_t;
+
+// Define then merge with another definition.
+typedef struct {} merged_after_definition;
+#include "c1.h"
index 61578a1865aa520c006d15cf7c174092b914dec7..216add76be2a6c87c4c47f8622c67ecf05714b34 100644 (file)
@@ -1,2 +1,3 @@
 module a { header "a.h" export * }
 module b { header "b.h" export * }
+module c { module c1 { header "c1.h" export * } module c2 { header "c2.h" export * } }
index 75534bd661b9615f8ed2d9fe5e0074be1d487f2a..1fd16865ca7b99faaa67258604ea4d7e0451d41b 100644 (file)
@@ -7,3 +7,4 @@ typedef pthread_mutex_t pthread_mutex_t;
 pthread_mutex_t x;
 #include "b.h"
 pthread_mutex_t y;
+merged_after_definition z;