In Microsoft mode, warn if an indirect goto jump over a variable initialization.

Also add a test case for the non Microsoft case because such test didn't exist.

llvm-svn: 139971
This commit is contained in:
Francois Pichet 2011-09-16 23:15:32 +00:00
parent 09a9b6b953
commit 2f55019bf0
3 changed files with 26 additions and 10 deletions

View File

@ -485,7 +485,8 @@ void JumpScopeChecker::VerifyJumps() {
if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
LabelDecl *Target = IGS->getConstantTarget();
CheckJump(IGS, Target->getStmt(), IGS->getGotoLoc(),
diag::err_goto_into_protected_scope, 0);
diag::err_goto_into_protected_scope,
diag::warn_goto_into_protected_scope);
continue;
}
@ -693,7 +694,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
SmallVector<unsigned, 10> ToScopesError;
SmallVector<unsigned, 10> ToScopesWarning;
for (unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
if (S.getLangOptions().Microsoft &&
if (S.getLangOptions().Microsoft && JumpDiagWarning != 0 &&
IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag))
ToScopesWarning.push_back(I);
else if (Scopes[I].InDiag)

View File

@ -258,14 +258,6 @@ void f()
}
namespace ms_protected_scope {
struct C { C(); };
@ -305,6 +297,14 @@ void exception_jump() {
} catch(int) {
}
}
int jump_over_indirect_goto() {
static void *ps[] = { &&a0 };
goto *&&a0; // expected-warning {{goto into protected scope}}
int a = 3; // expected-note {{jump bypasses variable initialization}}
a0:
return 0;
}
}

View File

@ -191,4 +191,19 @@ bool recurse() {
break;
}
}
namespace test10 {
int test() {
static void *ps[] = { &&a0 };
goto *&&a0; // expected-error {{goto into protected scope}}
int a = 3; // expected-note {{jump bypasses variable initialization}}
a0:
return 0;
}
}
}