[modules] Write out identifiers if the ID is local, too.

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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264913 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vassil Vassilev 2016-03-30 20:16:03 +00:00
parent 89f05c3944
commit f7eadeaffa
6 changed files with 18 additions and 1 deletions

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

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
namespace std {}
namespace std { enum float_round_style { denorm_present }; }
#include "TSchemaHelper.h"

View File

@ -0,0 +1 @@
namespace std { enum float_round_style { denorm_present }; }

View File

@ -0,0 +1,2 @@
module "Rtypes.h" { header "Rtypes.h" header "TGenericClassInfo.h" }
module "TSchemaHelper.h" { header "TSchemaHelper.h" }

7
test/Modules/pr27041.cpp Normal file
View File

@ -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