diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-19 05:21:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-19 05:21:20 +0000 |
commit | 38c5ebd7b1b65304c7b5c7b9bf3f9162df22e77d (patch) | |
tree | f35fc7fc5142abf6533b8e22f9dc80dccd7a0e49 /lib/Sema/SemaDecl.cpp | |
parent | 4f9c06ae362c10af797957b92a46fe91d5874899 (diff) |
add a new Sema::CurFunctionNeedsScopeChecking bool that is used to avoid
calling into the jump checker when a function or method is known to contain
no VLAs or @try blocks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 887c86cef5..7ed0e2dd31 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1564,11 +1564,13 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, InvalidDecl = true; } - if (S->getFnParent() == 0) { - QualType T = NewTD->getUnderlyingType(); - // C99 6.7.7p2: If a typedef name specifies a variably modified type - // then it shall have block scope. - if (T->isVariablyModifiedType()) { + // C99 6.7.7p2: If a typedef name specifies a variably modified type + // then it shall have block scope. + QualType T = NewTD->getUnderlyingType(); + if (T->isVariablyModifiedType()) { + CurFunctionNeedsScopeChecking = true; + + if (S->getFnParent() == 0) { bool SizeIsNegative; QualType FixedTy = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative); @@ -1810,9 +1812,12 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, && !NewVD->hasAttr<BlocksAttr>()) Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); - bool isIllegalVLA = T->isVariableArrayType() && NewVD->hasGlobalStorage(); - bool isIllegalVM = T->isVariablyModifiedType() && NewVD->hasLinkage(); - if (isIllegalVLA || isIllegalVM) { + bool isVM = T->isVariablyModifiedType(); + if (isVM || NewVD->hasAttr<CleanupAttr>()) + CurFunctionNeedsScopeChecking = true; + + if ((isVM && NewVD->hasLinkage()) || + (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { bool SizeIsNegative; QualType FixedTy = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative); @@ -2822,6 +2827,8 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { FunctionDecl *FD = cast<FunctionDecl>(D.getAs<Decl>()); + CurFunctionNeedsScopeChecking = false; + // See if this is a redefinition. const FunctionDecl *Definition; if (FD->getBody(Context, Definition)) { @@ -2964,7 +2971,8 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) { if (!Body) return D; // Verify that that gotos and switch cases don't jump into scopes illegally. - DiagnoseInvalidJumps(Body); + if (CurFunctionNeedsScopeChecking) + DiagnoseInvalidJumps(Body); return D; } |