[modules] Write out identifiers if the ID is local, too.
authorVassil Vassilev <v.g.vassilev@gmail.com>
Wed, 30 Mar 2016 20:16:03 +0000 (20:16 +0000)
committerVassil Vassilev <v.g.vassilev@gmail.com>
Wed, 30 Mar 2016 20:16:03 +0000 (20:16 +0000)
In some cases a slot for an identifier is requested but it gets written to
another module, causing an assertion.

At the point when we start serializing Rtypes, we have no imported IdentifierID
for float_round_style. We start serializing stuff and allocate an ID for it.
Then, during the serialization process, we pull in the identifier info for it
from TSchemaHelper. Finally, WriteIdentifierTable decides that the identifier
has not changed since it was deserialized, so doesn't emit it.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27041

Discussed on IRC with Richard Smith. Agreed on post commit review if needed.

llvm-svn: 264913

clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/Inputs/PR27041/Rtypes.h [new file with mode: 0644]
clang/test/Modules/Inputs/PR27041/TGenericClassInfo.h [new file with mode: 0644]
clang/test/Modules/Inputs/PR27041/TSchemaHelper.h [new file with mode: 0644]
clang/test/Modules/Inputs/PR27041/module.modulemap [new file with mode: 0644]
clang/test/Modules/pr27041.cpp [new file with mode: 0644]

index a828d35..78fc6eb 100644 (file)
@@ -3340,7 +3340,10 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
       auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first);
       IdentID ID = IdentIDPair.second;
       assert(II && "NULL identifier in identifier table");
-      if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization() ||
+      // Write out identifiers if either the ID is local or the identifier has
+      // changed since it was loaded.
+      if (ID >= FirstIdentID || !Chain || !II->isFromAST()
+          || II->hasChangedSinceDeserialization() ||
           (Trait.needDecls() &&
            II->hasFETokenInfoChangedSinceDeserialization()))
         Generator.insert(II, ID, Trait);
diff --git a/clang/test/Modules/Inputs/PR27041/Rtypes.h b/clang/test/Modules/Inputs/PR27041/Rtypes.h
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/clang/test/Modules/Inputs/PR27041/TGenericClassInfo.h b/clang/test/Modules/Inputs/PR27041/TGenericClassInfo.h
new file mode 100644 (file)
index 0000000..b43b2c9
--- /dev/null
@@ -0,0 +1,3 @@
+namespace std {}
+namespace std { enum float_round_style { denorm_present }; }
+#include "TSchemaHelper.h"
diff --git a/clang/test/Modules/Inputs/PR27041/TSchemaHelper.h b/clang/test/Modules/Inputs/PR27041/TSchemaHelper.h
new file mode 100644 (file)
index 0000000..31f726f
--- /dev/null
@@ -0,0 +1 @@
+namespace std { enum float_round_style { denorm_present }; }
diff --git a/clang/test/Modules/Inputs/PR27041/module.modulemap b/clang/test/Modules/Inputs/PR27041/module.modulemap
new file mode 100644 (file)
index 0000000..f0147cd
--- /dev/null
@@ -0,0 +1,2 @@
+module "Rtypes.h" { header "Rtypes.h" header "TGenericClassInfo.h" }
+module "TSchemaHelper.h" { header "TSchemaHelper.h" }
diff --git a/clang/test/Modules/pr27041.cpp b/clang/test/Modules/pr27041.cpp
new file mode 100644 (file)
index 0000000..9d06468
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR27041 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR27041/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR27041 -verify %s
+
+#include "Rtypes.h"
+
+// expected-no-diagnostics