[modules] Fix iterator invalidation issue with names being added to a module

while we're writing out the identifier table.

llvm-svn: 231890
This commit is contained in:
Richard Smith 2015-03-11 00:00:51 +00:00
parent b93fb82b3f
commit 9ab4ccecb3
5 changed files with 34 additions and 6 deletions

View File

@ -4428,16 +4428,19 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
// Make sure all decls associated with an identifier are registered for
// serialization.
llvm::SmallVector<const IdentifierInfo*, 256> IIsToVisit;
for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(),
IDEnd = PP.getIdentifierTable().end();
ID != IDEnd; ++ID) {
const IdentifierInfo *II = ID->second;
if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) {
for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II),
DEnd = SemaRef.IdResolver.end();
D != DEnd; ++D) {
GetDeclRef(*D);
}
if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization())
IIsToVisit.push_back(II);
}
for (const IdentifierInfo *II : IIsToVisit) {
for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II),
DEnd = SemaRef.IdResolver.end();
D != DEnd; ++D) {
GetDeclRef(*D);
}
}

View File

@ -0,0 +1,17 @@
// Ensure that loading 'i' introduces enough identifiers to cause the
// identifier table to be reallocated.
#define TYPEDEFS(x) typedef x##0 x; typedef x##1 x;
#define DEPTH_0(x) DEPTH_1(x##0) DEPTH_1(x##1) TYPEDEFS(x)
#define DEPTH_1(x) DEPTH_2(x##0) DEPTH_2(x##1) TYPEDEFS(x)
#define DEPTH_2(x) DEPTH_3(x##0) DEPTH_3(x##1) TYPEDEFS(x)
#define DEPTH_3(x) DEPTH_4(x##0) DEPTH_4(x##1) TYPEDEFS(x)
#define DEPTH_4(x) DEPTH_5(x##0) DEPTH_5(x##1) TYPEDEFS(x)
#define DEPTH_5(x) DEPTH_6(x##0) DEPTH_6(x##1) TYPEDEFS(x)
#define DEPTH_6(x) DEPTH_7(x##0) DEPTH_7(x##1) TYPEDEFS(x)
#define DEPTH_7(x) DEPTH_8(x##0) DEPTH_8(x##1) TYPEDEFS(x)
#define DEPTH_8(x) DEPTH_9(x##0) DEPTH_9(x##1) TYPEDEFS(x)
#define DEPTH_9(x) DEPTH_A(x##0) DEPTH_A(x##1) TYPEDEFS(x)
#define DEPTH_A(x) DEPTH_B(x##0) DEPTH_B(x##1) TYPEDEFS(x)
#define DEPTH_B(x) typedef int x;
DEPTH_0(i)
extern i v;

View File

@ -0,0 +1,2 @@
extern int v;
#include "a.h"

View File

@ -0,0 +1,2 @@
module a { header "a.h" }
module b { header "b.h" }

View File

@ -0,0 +1,4 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/invalidate-identifiers -emit-llvm-only %s
#include "b.h"