[clang] [Sema] Fix crash in __builtin_dump_struct with -Werror -Wformat-pedantic (PR #212377)

Krisitan Erik Olsen via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 17:02:13 PDT 2026


https://github.com/Kristianerik created https://github.com/llvm/llvm-project/pull/212377

`DiagnosticErrorTrap::hasErrorOccurred()` treats warnings promoted to errors by `-Werror` as real errors, causing `BuiltinDumpStructGenerator` to bail out before building the `PseudoObjectExpr` wrapper. CodeGen then encounters the untransformed `CallExpr` with a placeholder builtin type and hits `llvm_unreachable` in `CodeGenTypes::ConvertType`.
Use `hasUnrecoverableErrorOccurred()` instead, which ignores `-Werror` promoted warnings and only bails on genuine compilation errors.

Fixes #211943

>From dab6d16b50526e76e016e2381ce4d523b0a70150 Mon Sep 17 00:00:00 2001
From: Kristianerik <kristian.erik at outlook.com>
Date: Mon, 27 Jul 2026 16:57:09 -0700
Subject: [PATCH] [Sema] Fix crash in __builtin_dump_struct with -Werror
 -Wformat-pedantic

---
 clang/lib/Sema/SemaChecking.cpp    |  6 +++---
 clang/test/CodeGenCXX/GH211943.cpp | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/GH211943.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ef07e8c6133ed..d04dc8916e7c5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -541,9 +541,9 @@ struct BuiltinDumpStructGenerator {
     S.popCodeSynthesisContext();
     if (!RealCall.isInvalid())
       Actions.push_back(RealCall.get());
-    // Bail out if we've hit any errors, even if we managed to build the
-    // call. We don't want to produce more than one error.
-    return RealCall.isInvalid() || ErrorTracker.hasErrorOccurred();
+    // Bail out if we've hit any unrecoverable errors, even if we managed
+    // to build the call. 
+    return RealCall.isInvalid() || ErrorTracker.hasUnrecoverableErrorOccurred();
   }
 
   Expr *getIndentString(unsigned Depth) {
diff --git a/clang/test/CodeGenCXX/GH211943.cpp b/clang/test/CodeGenCXX/GH211943.cpp
new file mode 100644
index 0000000000000..729de892b7b55
--- /dev/null
+++ b/clang/test/CodeGenCXX/GH211943.cpp
@@ -0,0 +1,14 @@
+// RUN: not %clang_cc1 -Wformat-pedantic -Werror -emit-llvm -o /dev/null %s 2>&1 | FileCheck %s
+
+int printflike(const char *__restrict__ x, ...) __attribute__((__format__(__printf__, 1, 2)));
+
+struct Foo {
+    int *x;
+};
+
+void test() {
+    __builtin_dump_struct(&(struct Foo){0}, printflike);
+}
+
+// CHECK: error: format specifies type 'void *' but the argument has type 'int *'
+// CHECK-NOT: UNREACHABLE



More information about the cfe-commits mailing list