[llvm-branch-commits] [clang] release/22.x: [clang] Restore diagnostic for certain jumps into VLA(ish) scopes. (#175833) (PR #175858)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 13 14:28:49 PST 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/175858
Backport ac15ac9
Requested by: @keinflue
>From 6fdaa46d1ce677ec5f0f8a9d01d9c116f6fe1491 Mon Sep 17 00:00:00 2001
From: keinflue <keinflue at posteo.de>
Date: Tue, 13 Jan 2026 22:05:13 +0000
Subject: [PATCH] [clang] Restore diagnostic for certain jumps into VLA(ish)
scopes. (#175833)
Commit 543f112e148a enabled diagnostics for C++ compatibility for jumps
over initialization of variables. However, inadvertently this may cause
a prior diagnostic for jumps into scopes of variables with variably
modified types to be replaced with the less severe C++ compatibility
warning, resulting in impossible codegen.
This skips the check for the C++ compatibility warning if there is
already another diagnostic planned for the scope.
Fixes #175540
(cherry picked from commit ac15ac90e3ad3606b0a24de4c866b537fe41ceb7)
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/JumpDiagnostics.cpp | 4 +++-
clang/test/Sema/scope-check.c | 8 ++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c11a604a46d83..192db30db9b3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -672,6 +672,8 @@ Miscellaneous Bug Fixes
Miscellaneous Clang Crashes Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed a crash when attempting to jump over initialization of a variable with variably modified type. (#GH175540)
+
OpenACC Specific Changes
------------------------
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index 36c9d9afb37f1..2c45de69e7cdf 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -179,8 +179,10 @@ static ScopePair GetDiagForGotoScopeDecl(Sema &S, const Decl *D) {
}
}
+ // An earlier diag::note_protected_by_vla is more severe, so don't overwrite
+ // it here.
if (const Expr *Init = VD->getInit();
- VD->hasLocalStorage() && Init && !Init->containsErrors()) {
+ !InDiag && VD->hasLocalStorage() && Init && !Init->containsErrors()) {
// C++11 [stmt.dcl]p3:
// A program that jumps from a point where a variable with automatic
// storage duration is not in scope to a point where it is in scope
diff --git a/clang/test/Sema/scope-check.c b/clang/test/Sema/scope-check.c
index c6aa421b3ebde..f0100759ca9b2 100644
--- a/clang/test/Sema/scope-check.c
+++ b/clang/test/Sema/scope-check.c
@@ -256,3 +256,11 @@ void GH63682() {
(void)({P:1;}); // expected-note {{jump enters a statement expression}}
}
}
+
+void gh175549(int b, void* c) {
+ __asm__ goto("" : : : : d); // expected-error {{cannot jump from this asm goto statement to one of its possible targets}}
+ int(*a)[b] = c; // expected-note {{jump bypasses initialization of variable length array}}
+d: // expected-note {{possible target of asm goto statement}}
+ (void)a[0];
+}
+
More information about the llvm-branch-commits
mailing list