Skip to content

Conversation

@zmodem
Copy link
Collaborator

@zmodem zmodem commented May 5, 2025

Follow-up to #138009 which added diagnostics for "jump past initialization" in C mode, in which case they're not an MS extension.

Follow-up to llvm#138009 which added diagnostics for "jump past
initialization" in C mode, in which case they're not an MS extension.
@zmodem zmodem requested a review from AaronBallman May 5, 2025 11:20
@zmodem zmodem added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label May 5, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 5, 2025
@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-clang

Author: Hans Wennborg (zmodem)

Changes

Follow-up to #138009 which added diagnostics for "jump past initialization" in C mode, in which case they're not an MS extension.


Full diff: https://github.com/llvm/llvm-project/pull/138507.diff

2 Files Affected:

  • (modified) clang/lib/Sema/JumpDiagnostics.cpp (+2-1)
  • (modified) clang/test/Sema/warn-jump-bypasses-init.c (+1)
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index 6d71b26801107..a852a950b47f4 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -998,7 +998,8 @@ 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.getLangOpts().MSVCCompat && JumpDiagWarning != 0 &&
+    if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus &&
+        JumpDiagWarning != 0 &&
         IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag))
       ToScopesWarning.push_back(I);
     else if (IsCXX98CompatWarning(S, Scopes[I].InDiag) ||
diff --git a/clang/test/Sema/warn-jump-bypasses-init.c b/clang/test/Sema/warn-jump-bypasses-init.c
index a9604742bf50c..53f10722406cd 100644
--- a/clang/test/Sema/warn-jump-bypasses-init.c
+++ b/clang/test/Sema/warn-jump-bypasses-init.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wjump-bypasses-init %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wc++-compat %s
 // RUN: %clang_cc1 -fsyntax-only -verify=good %s
+// RUN: %clang_cc1 -fsyntax-only -verify=good -fms-compatibility %s
 // RUN: %clang_cc1 -fsyntax-only -verify=cxx,both -x c++ %s
 // good-no-diagnostics
 

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for catching this!

@zmodem zmodem merged commit a94e560 into llvm:main May 5, 2025
11 of 15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Follow-up to llvm#138009 which added diagnostics for "jump past
initialization" in C mode, in which case they're not an MS extension.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
Follow-up to llvm#138009 which added diagnostics for "jump past
initialization" in C mode, in which case they're not an MS extension.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants