[clang] [Sema] Fix crash in __builtin_dump_struct with -Werror -Wformat-pedantic (PR #212377)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 17:02:58 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Krisitan Erik Olsen (Kristianerik)
<details>
<summary>Changes</summary>
`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
---
Full diff: https://github.com/llvm/llvm-project/pull/212377.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaChecking.cpp (+3-3)
- (added) clang/test/CodeGenCXX/GH211943.cpp (+14)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/212377
More information about the cfe-commits
mailing list