Skip to content

Commit d79514e

Browse files
committed
[modules] Separately track whether an identifier's preprocessor information and
name lookup information have changed since deserialization. For a C++ modules build, we do not need to re-emit the identifier into the serialized identifier table if only the name lookup information has changed (and in all cases, we don't need to re-emit the macro information if only the name lookup information has changed). llvm-svn: 259901
1 parent 1242ce9 commit d79514e

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ class IdentifierInfo {
6262
// partially) from an AST file.
6363
bool ChangedAfterLoad : 1; // True if identifier has changed from the
6464
// definition loaded from an AST file.
65+
bool FEChangedAfterLoad : 1; // True if identifier's frontend information
66+
// has changed from the definition loaded
67+
// from an AST file.
6568
bool RevertedTokenID : 1; // True if revertTokenIDToIdentifier was
6669
// called.
6770
bool OutOfDate : 1; // True if there may be additional
6871
// information about this identifier
6972
// stored externally.
7073
bool IsModulesImport : 1; // True if this is the 'import' contextual
7174
// keyword.
72-
// 30 bit left in 64-bit word.
75+
// 29 bit left in 64-bit word.
7376

7477
void *FETokenInfo; // Managed by the language front-end.
7578
llvm::StringMapEntry<IdentifierInfo*> *Entry;
@@ -303,6 +306,18 @@ class IdentifierInfo {
303306
ChangedAfterLoad = true;
304307
}
305308

309+
/// \brief Determine whether the frontend token information for this
310+
/// identifier has changed since it was loaded from an AST file.
311+
bool hasFETokenInfoChangedSinceDeserialization() const {
312+
return FEChangedAfterLoad;
313+
}
314+
315+
/// \brief Note that the frontend token information for this identifier has
316+
/// changed since it was loaded from an AST file.
317+
void setFETokenInfoChangedSinceDeserialization() {
318+
FEChangedAfterLoad = true;
319+
}
320+
306321
/// \brief Determine whether the information for this identifier is out of
307322
/// date with respect to the external source.
308323
bool isOutOfDate() const { return OutOfDate; }

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ IdentifierInfo::IdentifierInfo() {
4242
NeedsHandleIdentifier = false;
4343
IsFromAST = false;
4444
ChangedAfterLoad = false;
45+
FEChangedAfterLoad = false;
4546
RevertedTokenID = false;
4647
OutOfDate = false;
4748
IsModulesImport = false;

clang/lib/Sema/IdentifierResolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
381381
PP.getExternalSource()->updateOutOfDateIdentifier(II);
382382

383383
if (II.isFromAST())
384-
II.setChangedSinceDeserialization();
384+
II.setFETokenInfoChangedSinceDeserialization();
385385
}
386386

387387
//===----------------------------------------------------------------------===//

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,8 @@ class ASTIdentifierTableTrait {
31623162
NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus),
31633163
InterestingIdentifierOffsets(InterestingIdentifierOffsets) {}
31643164

3165+
bool needDecls() const { return NeedDecls; }
3166+
31653167
static hash_value_type ComputeHash(const IdentifierInfo* II) {
31663168
return llvm::HashString(II->getName());
31673169
}
@@ -3307,7 +3309,9 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
33073309
auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first);
33083310
IdentID ID = IdentIDPair.second;
33093311
assert(II && "NULL identifier in identifier table");
3310-
if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization())
3312+
if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization() ||
3313+
(Trait.needDecls() &&
3314+
II->hasFETokenInfoChangedSinceDeserialization()))
33113315
Generator.insert(II, ID, Trait);
33123316
}
33133317

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: echo 'extern int some_long_variable_name;' > %t/x.h
4+
// RUN: echo 'extern int some_long_variable_name;' > %t/y.h
5+
// RUN: echo 'module X { header "x.h" } module Y { header "y.h" }' > %t/map
6+
// RUN: %clang_cc1 -fmodules -x c++ -fmodule-name=X %t/map -emit-module -o %t/x.pcm
7+
// RUN: %clang_cc1 -fmodules -x c++ -fmodule-name=Y %t/map -fmodule-file=%t/x.pcm -emit-module -o %t/y.pcm
8+
// RUN: cat %t/y.pcm | FileCheck %s
9+
//
10+
// CHECK-NOT: some_long_variable_name

0 commit comments

Comments
 (0)