[modules] When reading / writing a typedef that is a name for linkage for

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.

llvm-svn: 293219
This commit is contained in:
Richard Smith 2017-01-26 22:39:55 +00:00
parent abb5b7965a
commit c0ca4c2c95
5 changed files with 12 additions and 0 deletions

View 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;
}

View 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) {

View File

@ -1 +1,5 @@
typedef union {} pthread_mutex_t;
// Define then merge with another definition.
typedef struct {} merged_after_definition;
#include "c1.h"

View 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 * } }

View 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;