aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-21 17:11:58 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-21 17:11:58 +0000
commitb6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2 (patch)
tree9d574fc3b816875c30e2e97338b0fa8338fb3079 /lib/Sema/Sema.cpp
parent69667a03e07a052170f09226ef7614ca8ab21ac7 (diff)
Explictly track tentative definitions within Sema, then hand those
tentative definitions off to the ASTConsumer at the end of the translation unit. Eliminate CodeGen's internal tracking of tentative definitions, and instead hook into ASTConsumer::CompleteTentativeDefinition. Also, tweak the definition-deferal logic for C++, where there are no tentative definitions. Fixes <rdar://problem/6808352>, and will make it much easier for precompiled headers to cope with tentative definitions in the future. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69681 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r--lib/Sema/Sema.cpp65
1 files changed, 32 insertions, 33 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index ed5c431da8..19155b6cc3 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "Sema.h"
+#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
@@ -232,41 +233,39 @@ 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.
- if (!getLangOptions().CPlusPlus) {
- // Note: we traverse the scope's list of declarations rather than
- // the DeclContext's list, because we only want to see the most
- // recent declaration of each identifier.
- for (Scope::decl_iterator I = TUScope->decl_begin(),
- IEnd = TUScope->decl_end();
- I != IEnd; ++I) {
- Decl *D = (*I).getAs<Decl>();
- if (D->isInvalidDecl())
- continue;
+ for (llvm::DenseMap<DeclarationName, VarDecl *>::iterator
+ D = TentativeDefinitions.begin(),
+ DEnd = TentativeDefinitions.end();
+ D != DEnd; ++D) {
+ VarDecl *VD = D->second;
- if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
- if (VD->isTentativeDefinition(Context)) {
- if (const IncompleteArrayType *ArrayT
- = Context.getAsIncompleteArrayType(VD->getType())) {
- if (RequireCompleteType(VD->getLocation(),
- ArrayT->getElementType(),
- 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.getConstantArrayType(ArrayT->getElementType(),
- One, ArrayType::Normal, 0);
- VD->setType(T);
- }
- } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
- diag::err_tentative_def_incomplete_type))
- VD->setInvalidDecl();
- }
+ if (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))
+ 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.getConstantArrayType(ArrayT->getElementType(),
+ One, ArrayType::Normal, 0);
+ VD->setType(T);
}
- }
+ } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
+ diag::err_tentative_def_incomplete_type))
+ VD->setInvalidDecl();
+
+ // Notify the consumer that we've completed a tentative definition.
+ if (!VD->isInvalidDecl())
+ Consumer.CompleteTentativeDefinition(VD);
+
}
}