aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaDecl.cpp58
-rw-r--r--lib/Sema/SemaDeclCXX.cpp9
-rw-r--r--lib/Sema/SemaStmt.cpp17
3 files changed, 40 insertions, 44 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 328741ec0f..6d41fce555 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -372,26 +372,23 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
return New;
}
// We've verified the types match, now handle "tentative" definitions.
- FileVarDecl *OldFSDecl = dyn_cast<FileVarDecl>(Old);
- FileVarDecl *NewFSDecl = dyn_cast<FileVarDecl>(New);
-
- if (OldFSDecl && NewFSDecl) {
+ if (Old->isFileVarDecl() && New->isFileVarDecl()) {
// Handle C "tentative" external object definitions (C99 6.9.2).
bool OldIsTentative = false;
bool NewIsTentative = false;
- if (!OldFSDecl->getInit() &&
- (OldFSDecl->getStorageClass() == VarDecl::None ||
- OldFSDecl->getStorageClass() == VarDecl::Static))
+ if (!Old->getInit() &&
+ (Old->getStorageClass() == VarDecl::None ||
+ Old->getStorageClass() == VarDecl::Static))
OldIsTentative = true;
// FIXME: this check doesn't work (since the initializer hasn't been
// attached yet). This check should be moved to FinalizeDeclaratorGroup.
// Unfortunately, by the time we get to FinializeDeclaratorGroup, we've
// thrown out the old decl.
- if (!NewFSDecl->getInit() &&
- (NewFSDecl->getStorageClass() == VarDecl::None ||
- NewFSDecl->getStorageClass() == VarDecl::Static))
+ if (!New->getInit() &&
+ (New->getStorageClass() == VarDecl::None ||
+ New->getStorageClass() == VarDecl::Static))
; // change to NewIsTentative = true; once the code is moved.
if (NewIsTentative || OldIsTentative)
@@ -880,13 +877,11 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
R.getAsString());
InvalidDecl = true;
}
- NewVD = FileVarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
- II, R, SC,
- LastDeclarator);
+ NewVD = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+ II, R, SC, LastDeclarator);
} else {
- NewVD = BlockVarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
- II, R, SC,
- LastDeclarator);
+ NewVD = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+ II, R, SC, LastDeclarator);
}
// Handle attributes prior to checking for duplicates in MergeVarDecl
HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
@@ -952,23 +947,23 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
// Get the decls type and save a reference for later, since
// CheckInitializerTypes may change it.
QualType DclT = VDecl->getType(), SavT = DclT;
- if (BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(VDecl)) {
- VarDecl::StorageClass SC = BVD->getStorageClass();
+ if (VDecl->isBlockVarDecl()) {
+ VarDecl::StorageClass SC = VDecl->getStorageClass();
if (SC == VarDecl::Extern) { // C99 6.7.8p5
Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
- BVD->setInvalidDecl();
- } else if (!BVD->isInvalidDecl()) {
+ VDecl->setInvalidDecl();
+ } else if (!VDecl->isInvalidDecl()) {
if (CheckInitializerTypes(Init, DclT))
- BVD->setInvalidDecl();
+ VDecl->setInvalidDecl();
if (SC == VarDecl::Static) // C99 6.7.8p4.
CheckForConstantInitializer(Init, DclT);
}
- } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(VDecl)) {
- if (FVD->getStorageClass() == VarDecl::Extern)
+ } else if (VDecl->isFileVarDecl()) {
+ if (VDecl->getStorageClass() == VarDecl::Extern)
Diag(VDecl->getLocation(), diag::warn_extern_init);
- if (!FVD->isInvalidDecl())
+ if (!VDecl->isInvalidDecl())
if (CheckInitializerTypes(Init, DclT))
- FVD->setInvalidDecl();
+ VDecl->setInvalidDecl();
// C99 6.7.8p4. All file scoped initializers need to be constant.
CheckForConstantInitializer(Init, DclT);
@@ -1012,13 +1007,12 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
VarDecl *IDecl = dyn_cast<VarDecl>(ID);
if (!IDecl)
continue;
- FileVarDecl *FVD = dyn_cast<FileVarDecl>(IDecl);
- BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(IDecl);
QualType T = IDecl->getType();
// C99 6.7.5.2p2: If an identifier is declared to be an object with
// static storage duration, it shall not have a variable length array.
- if ((FVD || BVD) && IDecl->getStorageClass() == VarDecl::Static) {
+ if ((IDecl->isFileVarDecl() || IDecl->isBlockVarDecl()) &&
+ IDecl->getStorageClass() == VarDecl::Static) {
if (T->getAsVariableArrayType()) {
Diag(IDecl->getLocation(), diag::err_typecheck_illegal_vla);
IDecl->setInvalidDecl();
@@ -1026,7 +1020,8 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
}
// Block scope. C99 6.7p7: If an identifier for an object is declared with
// no linkage (C99 6.2.2p6), the type for the object shall be complete...
- if (BVD && IDecl->getStorageClass() != VarDecl::Extern) {
+ if (IDecl->isBlockVarDecl() &&
+ IDecl->getStorageClass() != VarDecl::Extern) {
if (T->isIncompleteType() && !IDecl->isInvalidDecl()) {
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
T.getAsString());
@@ -1038,8 +1033,9 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
// storage-class specifier or with the storage-class specifier "static",
// constitutes a tentative definition. Note: A tentative definition with
// external linkage is valid (C99 6.2.2p5).
- if (FVD && !FVD->getInit() && (FVD->getStorageClass() == VarDecl::Static ||
- FVD->getStorageClass() == VarDecl::None)) {
+ if (IDecl && !IDecl->getInit() &&
+ (IDecl->getStorageClass() == VarDecl::Static ||
+ IDecl->getStorageClass() == VarDecl::None)) {
if (T->isIncompleteArrayType()) {
// C99 6.9.2 (p2, p5): Implicit initialization causes an incomplete
// array to be completed. Don't issue a diagnostic.
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 7202d2f2f1..251fb5e72b 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -74,13 +74,14 @@ namespace {
return S->Diag(DRE->getSourceRange().getBegin(),
diag::err_param_default_argument_references_param,
Param->getName(), DefaultArg->getSourceRange());
- } else if (BlockVarDecl *BlockVar = dyn_cast<BlockVarDecl>(Decl)) {
+ } else if (VarDecl *VDecl = dyn_cast<VarDecl>(Decl)) {
// C++ [dcl.fct.default]p7
// Local variables shall not be used in default argument
// expressions.
- return S->Diag(DRE->getSourceRange().getBegin(),
- diag::err_param_default_argument_references_local,
- BlockVar->getName(), DefaultArg->getSourceRange());
+ if (VDecl->isBlockVarDecl())
+ return S->Diag(DRE->getSourceRange().getBegin(),
+ diag::err_param_default_argument_references_local,
+ VDecl->getName(), DefaultArg->getSourceRange());
}
// FIXME: when Clang has support for member functions, "this"
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 14b2fdf7d0..d8f213a973 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -521,10 +521,10 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
- BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
- if (BVD && !BVD->hasLocalStorage())
- BVD = 0;
- if (BVD == 0)
+ VarDecl *VD = dyn_cast<VarDecl>(D);
+ if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage())
+ VD = 0;
+ if (VD == 0)
Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
diag::err_non_variable_decl_in_for);
// FIXME: mark decl erroneous!
@@ -556,13 +556,12 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
ScopedDecl *D = DS->getDecl();
- BlockVarDecl *BVD = cast<BlockVarDecl>(D);
- if (!BVD->hasLocalStorage())
- return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
+ VarDecl *VD = cast<VarDecl>(D);
+ if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
+ return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
if (D->getNextDeclarator())
return Diag(D->getLocation(), diag::err_toomany_element_decls);
- }
- else
+ } else
FirstType = static_cast<Expr*>(first)->getType();
if (!isObjCObjectPointerType(FirstType))
Diag(ForLoc, diag::err_selector_element_type,