[clang] [Clang][Sema] Fix crash with asm goto and OpenMP pragma (PR #179368)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 2 17:47:23 PST 2026
https://github.com/nataliakokoromyti created https://github.com/llvm/llvm-project/pull/179368
We were getting a segfault when using asm goto with an undeclared label inside an OpenMP pragma (see issue #179238). The issue was that when you have an undeclared label in an OpenMP scope, Target (which is a LabelDecl*) can be null. The code was just assuming it was always valid and dereferencing it without checking. Just adding a null check before using Target fixes it. Still reports the errors (undeclared label, invalid jump, etc.) but doesn't segfault.
>From cc1c58a8e75cbcfadc6d586a199fe7a2a29d025e Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 2 Feb 2026 17:42:23 -0800
Subject: [PATCH] [Clang][Sema] Fix crash with asm goto and OpenMP pragma
---
clang/lib/Sema/JumpDiagnostics.cpp | 3 ++-
clang/test/Sema/openmp-asm-goto-crash.c | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Sema/openmp-asm-goto-crash.c
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index 2c45de69e7cdf..f7bc8dea5fa75 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -916,7 +916,8 @@ static void DiagnoseIndirectOrAsmJumpStmt(Sema &S, Stmt *Jump,
bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
S.Diag(Jump->getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
<< IsAsmGoto;
- S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
+ if (Target && Target->getStmt())
+ S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
<< IsAsmGoto;
Diagnosed = true;
}
diff --git a/clang/test/Sema/openmp-asm-goto-crash.c b/clang/test/Sema/openmp-asm-goto-crash.c
new file mode 100644
index 0000000000000..7429573b4c2db
--- /dev/null
+++ b/clang/test/Sema/openmp-asm-goto-crash.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify -triple x86_64-unknown-linux-gnu %s
+
+int test_asm_goto_undeclared_label() {
+#pragma omp assume
+ __asm__ goto("" : : : : undefined_label); // expected-error {{use of undeclared label 'undefined_label'}} \
+ // expected-error {{cannot jump from this asm goto statement to one of its possible targets}} \
+ // expected-note {{jump exits scope of OpenMP structured block}}
+ int x = 1;
+undefined_label:
+ return x;
+}
More information about the cfe-commits
mailing list