FunctionScopeInfo::~FunctionScopeInfo() { }
void FunctionScopeInfo::Clear(unsigned NumErrors) {
- NeedsScopeChecking = false;
+ HasBranchProtectedScope = false;
+ HasBranchIntoScope = false;
+ HasIndirectGoto = false;
+
LabelMap.clear();
SwitchStack.clear();
Returns.clear();
/// a block.
bool IsBlockInfo;
- /// \brief Set true when a function, method contains a VLA or ObjC try block,
- /// which introduce scopes that need to be checked for goto conditions. If a
- /// function does not contain this, then it need not have the jump checker run
- /// on it.
- bool NeedsScopeChecking;
+ /// \brief Whether this function contains a VLA, @try, try, C++
+ /// initializer, or anything else that can't be jumped past.
+ bool HasBranchProtectedScope;
+
+ /// \brief Whether this function contains any switches or direct gotos.
+ bool HasBranchIntoScope;
+
+ /// \brief Whether this function contains any indirect gotos.
+ bool HasIndirectGoto;
/// \brief The number of errors that had occurred before starting this
/// function or block.
/// block, if there is any chance of applying the named return value
/// optimization.
llvm::SmallVector<ReturnStmt *, 4> Returns;
+
+ bool NeedsScopeChecking() const {
+ return HasIndirectGoto ||
+ (HasBranchProtectedScope && HasBranchIntoScope);
+ }
FunctionScopeInfo(unsigned NumErrors)
- : IsBlockInfo(false), NeedsScopeChecking(false),
+ : IsBlockInfo(false),
+ HasBranchProtectedScope(false),
+ HasBranchIntoScope(false),
+ HasIndirectGoto(false),
NumErrorsAtStartOfFunction(NumErrors) { }
virtual ~FunctionScopeInfo();
/// \brief Determine whether the current function or block needs scope
/// checking.
- bool &FunctionNeedsScopeChecking() {
- if (FunctionScopes.empty())
- return TopFunctionScope.NeedsScopeChecking;
+ bool FunctionNeedsScopeChecking() {
+ if (!FunctionScopes.empty())
+ return FunctionScopes.back()->NeedsScopeChecking();
+ return false;
+ }
- return FunctionScopes.back()->NeedsScopeChecking;
+ void setFunctionHasBranchIntoScope() {
+ if (!FunctionScopes.empty())
+ FunctionScopes.back()->HasBranchIntoScope = true;
}
+ void setFunctionHasBranchProtectedScope() {
+ if (!FunctionScopes.empty())
+ FunctionScopes.back()->HasBranchProtectedScope = true;
+ }
+
+ void setFunctionHasIndirectGoto() {
+ if (!FunctionScopes.empty())
+ FunctionScopes.back()->HasIndirectGoto = true;
+ }
+
+
bool hasAnyErrorsInThisFunction() const;
/// \brief Retrieve the current block, if any.
// then it shall have block scope.
QualType T = NewTD->getUnderlyingType();
if (T->isVariablyModifiedType()) {
- FunctionNeedsScopeChecking() = true;
+ setFunctionHasBranchProtectedScope();
if (S->getFnParent() == 0) {
bool SizeIsNegative;
bool isVM = T->isVariablyModifiedType();
if (isVM || NewVD->hasAttr<CleanupAttr>() ||
NewVD->hasAttr<BlocksAttr>() ||
- // FIXME: We need to diagnose jumps passed initialized variables in C++.
- // However, this turns on the scope checker for everything with a variable
- // which may impact compile time. See if we can find a better solution
- // to this, perhaps only checking functions that contain gotos in C++?
(LangOpts.CPlusPlus && NewVD->hasLocalStorage()))
- FunctionNeedsScopeChecking() = true;
+ setFunctionHasBranchProtectedScope();
if ((isVM && NewVD->hasLinkage()) ||
(T->isVariableArrayType() && NewVD->hasGlobalStorage())) {
if (!CondExpr)
return StmtError();
}
+
+ setFunctionHasBranchIntoScope();
SwitchStmt *SS = new (Context) SwitchStmt(Context, ConditionVar, CondExpr);
getSwitchStack().push_back(SS);
// Look up the record for this label identifier.
LabelStmt *&LabelDecl = getLabelMap()[LabelII];
+ setFunctionHasBranchIntoScope();
+
// If we haven't seen this label yet, create a forward reference.
if (LabelDecl == 0)
LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 0);
if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
return StmtError();
}
+
+ setFunctionHasIndirectGoto();
+
return Owned(new (Context) IndirectGotoStmt(GotoLoc, StarLoc, E));
}
Action::OwningStmtResult
Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, StmtArg Try,
MultiStmtArg CatchStmts, StmtArg Finally) {
- FunctionNeedsScopeChecking() = true;
+ setFunctionHasBranchProtectedScope();
unsigned NumCatchStmts = CatchStmts.size();
return Owned(ObjCAtTryStmt::Create(Context, AtLoc, Try.takeAs<Stmt>(),
(Stmt **)CatchStmts.release(),
Action::OwningStmtResult
Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr,
StmtArg SynchBody) {
- FunctionNeedsScopeChecking() = true;
+ setFunctionHasBranchProtectedScope();
// Make sure the expression type is an ObjC pointer or "void *".
Expr *SyncExpr = static_cast<Expr*>(SynchExpr.get());
}
}
+ setFunctionHasBranchProtectedScope();
+
// FIXME: We should detect handlers that cannot catch anything because an
// earlier handler catches a superclass. Need to find a method that is not
// quadratic for this.
// Neither of these are explicitly forbidden, but every compiler detects them
// and warns.
- FunctionNeedsScopeChecking() = true;
RawHandlers.release();
return Owned(CXXTryStmt::Create(Context, TryLoc,
static_cast<Stmt*>(TryBlock.release()),
typedef void *Opcode;
Opcode pr_4033_getOpcode();
void pr_4033(void) {
+ void *lbl = &&next_opcode;
next_opcode:
{
Opcode op = pr_4033_getOpcode();
-// RUN: %clang_cc1 -Wreturn-type < %s -emit-llvm
+// RUN: %clang_cc1 -Wreturn-type %s -emit-llvm
void test1(int x) {
switch (x) {
}
// PR3869
-int test5(long long b) { goto *b; }
+int test5(long long b) {
+ static void *lbls[] = { &&lbl };
+ goto *b;
+ lbl:
+ return 0;
+}