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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 14:39:55 PST 2017


Author: rsmith
Date: Thu Jan 26 16:39:55 2017
New Revision: 293219

URL: http://llvm.org/viewvc/llvm-project?rev=293219&view=rev
Log:
[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.

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

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=293219&r1=293218&r2=293219&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jan 26 16:39:55 2017
@@ -592,6 +592,11 @@ ASTDeclReader::VisitTypedefNameDecl(Type
     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;
 }
 

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=293219&r1=293218&r2=293219&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Jan 26 16:39:55 2017
@@ -368,6 +368,7 @@ void ASTDeclWriter::VisitTypedefNameDecl
   Record.push_back(D->isModed());
   if (D->isModed())
     Record.AddTypeRef(D->getUnderlyingType());
+  Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
 }
 
 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {

Modified: cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h?rev=293219&r1=293218&r2=293219&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h (original)
+++ cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h Thu Jan 26 16:39:55 2017
@@ -1 +1,5 @@
 typedef union {} pthread_mutex_t;
+
+// Define then merge with another definition.
+typedef struct {} merged_after_definition;
+#include "c1.h"

Modified: cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap?rev=293219&r1=293218&r2=293219&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap (original)
+++ cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap Thu Jan 26 16:39:55 2017
@@ -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 * } }

Modified: cfe/trunk/test/Modules/merge-name-for-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-name-for-linkage.cpp?rev=293219&r1=293218&r2=293219&view=diff
==============================================================================
--- cfe/trunk/test/Modules/merge-name-for-linkage.cpp (original)
+++ cfe/trunk/test/Modules/merge-name-for-linkage.cpp Thu Jan 26 16:39:55 2017
@@ -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;




More information about the cfe-commits mailing list