summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2009-09-08 23:37:20 +0000
committerTanya Lattner <tonic@nondot.org>2009-09-08 23:37:20 +0000
commit642a39bed267a97373b26de261b3886a81701c08 (patch)
treedca05a5297b1c36c40998399cde4da7e8dfd228f /clang/lib/Sema/Sema.cpp
parentMerge 81205 from mainline. (diff)
downloadllvm-project-642a39bed267a97373b26de261b3886a81701c08.tar.gz
llvm-project-642a39bed267a97373b26de261b3886a81701c08.tar.bz2
llvm-project-642a39bed267a97373b26de261b3886a81701c08.zip
Merge 81236 from mainline.
Fix PR4922, where Sema would complete tentative definitions in nondeterminstic order because it was doing so while iterating over a densemap. There are still similar problems in other places, for example WeakUndeclaredIdentifiers is still written to the PCH file in a nondeterminstic order, and we emit warnings about #pragma weak in nondeterminstic order. llvm-svn: 81280
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 5425c4fb5abc..92af38695526 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -247,13 +247,16 @@ void Sema::ActOnEndOfTranslationUnit() {
// template instantiations earlier.
PerformPendingImplicitInstantiations();
- // check for #pragma weak identifiers that were never declared
+ // Check for #pragma weak identifiers that were never declared
+ // FIXME: This will cause diagnostics to be emitted in a non-determinstic
+ // order! Iterating over a densemap like this is bad.
for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator
- I = WeakUndeclaredIdentifiers.begin(),
- E = WeakUndeclaredIdentifiers.end(); I != E; ++I) {
- if (!I->second.getUsed())
- Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared)
- << I->first;
+ I = WeakUndeclaredIdentifiers.begin(),
+ E = WeakUndeclaredIdentifiers.end(); I != E; ++I) {
+ if (I->second.getUsed()) continue;
+
+ Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared)
+ << I->first;
}
if (!CompleteTranslationUnit)
@@ -270,31 +273,30 @@ void Sema::ActOnEndOfTranslationUnit() {
// translation unit contains a file scope declaration of that
// identifier, with the composite type as of the end of the
// translation unit, with an initializer equal to 0.
- for (llvm::DenseMap<DeclarationName, VarDecl *>::iterator
- D = TentativeDefinitions.begin(),
- DEnd = TentativeDefinitions.end();
- D != DEnd; ++D) {
- VarDecl *VD = D->second;
-
- if (VD->isInvalidDecl() || !VD->isTentativeDefinition(Context))
+ for (unsigned i = 0, e = TentativeDefinitionList.size(); i != e; ++i) {
+ VarDecl *VD = TentativeDefinitions.lookup(TentativeDefinitionList[i]);
+
+ // If the tentative definition was completed, it will be in the list, but
+ // not the map.
+ if (VD == 0 || VD->isInvalidDecl() || !VD->isTentativeDefinition(Context))
continue;
if (const IncompleteArrayType *ArrayT
= Context.getAsIncompleteArrayType(VD->getType())) {
if (RequireCompleteType(VD->getLocation(),
ArrayT->getElementType(),
- diag::err_tentative_def_incomplete_type_arr))
+ diag::err_tentative_def_incomplete_type_arr)) {
VD->setInvalidDecl();
- else {
- // Set the length of the array to 1 (C99 6.9.2p5).
- Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
- llvm::APInt One(Context.getTypeSize(Context.getSizeType()),
- true);
- QualType T
- = Context.getConstantArrayWithoutExprType(ArrayT->getElementType(),
- One, ArrayType::Normal, 0);
- VD->setType(T);
+ continue;
}
+
+ // Set the length of the array to 1 (C99 6.9.2p5).
+ Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
+ llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
+ QualType T
+ = Context.getConstantArrayWithoutExprType(ArrayT->getElementType(),
+ One, ArrayType::Normal, 0);
+ VD->setType(T);
} else if (RequireCompleteType(VD->getLocation(), VD->getType(),
diag::err_tentative_def_incomplete_type))
VD->setInvalidDecl();