r231890 - [modules] Fix iterator invalidation issue with names being added to a module
Richard Smith
richard-llvm at metafoo.co.uk
Tue Mar 10 17:00:51 PDT 2015
Author: rsmith
Date: Tue Mar 10 19:00:51 2015
New Revision: 231890
URL: http://llvm.org/viewvc/llvm-project?rev=231890&view=rev
Log:
[modules] Fix iterator invalidation issue with names being added to a module
while we're writing out the identifier table.
Added:
cfe/trunk/test/Modules/Inputs/invalidate-identifiers/
cfe/trunk/test/Modules/Inputs/invalidate-identifiers/a.h
cfe/trunk/test/Modules/Inputs/invalidate-identifiers/b.h
cfe/trunk/test/Modules/Inputs/invalidate-identifiers/module.modulemap
cfe/trunk/test/Modules/invalidate-identifiers.c
Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=231890&r1=231889&r2=231890&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Mar 10 19:00:51 2015
@@ -4428,16 +4428,19 @@ void ASTWriter::WriteASTCore(Sema &SemaR
// 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);
}
}
Added: cfe/trunk/test/Modules/Inputs/invalidate-identifiers/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/invalidate-identifiers/a.h?rev=231890&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/invalidate-identifiers/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/invalidate-identifiers/a.h Tue Mar 10 19:00:51 2015
@@ -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;
Added: cfe/trunk/test/Modules/Inputs/invalidate-identifiers/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/invalidate-identifiers/b.h?rev=231890&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/invalidate-identifiers/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/invalidate-identifiers/b.h Tue Mar 10 19:00:51 2015
@@ -0,0 +1,2 @@
+extern int v;
+#include "a.h"
Added: cfe/trunk/test/Modules/Inputs/invalidate-identifiers/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/invalidate-identifiers/module.modulemap?rev=231890&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/invalidate-identifiers/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/invalidate-identifiers/module.modulemap Tue Mar 10 19:00:51 2015
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Added: cfe/trunk/test/Modules/invalidate-identifiers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/invalidate-identifiers.c?rev=231890&view=auto
==============================================================================
--- cfe/trunk/test/Modules/invalidate-identifiers.c (added)
+++ cfe/trunk/test/Modules/invalidate-identifiers.c Tue Mar 10 19:00:51 2015
@@ -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"
More information about the cfe-commits
mailing list