From 2e96511773c6a21291dfa5218eb8ba79f04b5318 Mon Sep 17 00:00:00 2001 From: Francois Pichet Date: Fri, 16 Sep 2011 23:15:32 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/JumpDiagnostics.cpp | 5 +++-- test/SemaCXX/MicrosoftExtensions.cpp | 16 ++++++++-------- test/SemaCXX/scope-check.cpp | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 565a610b8c..fcc3154ebe 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -485,7 +485,8 @@ void JumpScopeChecker::VerifyJumps() { if (IndirectGotoStmt *IGS = dyn_cast(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 ToScopesError; SmallVector 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) diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index d92eda711c..396ee13f66 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -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; +} } diff --git a/test/SemaCXX/scope-check.cpp b/test/SemaCXX/scope-check.cpp index d656a074db..ec2f2e565f 100644 --- a/test/SemaCXX/scope-check.cpp +++ b/test/SemaCXX/scope-check.cpp @@ -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; +} + } + +} + -- 2.40.0