[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
Wed Jul 29 14:51:36 PDT 2026
https://github.com/Kristianerik updated https://github.com/llvm/llvm-project/pull/212377
>From 5a46bb74ce98a9f592e2045b0b12cef871a9b6bd 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/docs/ReleaseNotes.md | 2 ++
clang/lib/Sema/SemaChecking.cpp | 6 +++---
clang/test/CodeGenCXX/GH211943.cpp | 13 +++++++++++++
3 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 clang/test/CodeGenCXX/GH211943.cpp
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index cc340ede25c6b..89d1bcad734d9 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -350,6 +350,8 @@ features cannot lower the translation-unit ABI level;
- Fixed a crash when classifying a call to a builtin with dependent arguments,
such as when the call is used as an `auto` non-type template argument.
+- Fixed a crash in ``__builtin_dump_struct`` when ``-Werror`` promotes
+ format warnings to errors. (#GH211943)
#### Bug Fixes to Attribute Support
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ef07e8c6133ed..836c607111c02 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..a28a735a2e830
--- /dev/null
+++ b/clang/test/CodeGenCXX/GH211943.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -Wformat-pedantic -Werror -emit-llvm -o /dev/null -verify %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); // expected-error {{taking the address of a temporary object of type 'struct Foo'}} \
+ // expected-error {{format specifies type 'void *' but the argument has type 'int *'}} \
+ // expected-note {{in call to printing function}}
+}
More information about the cfe-commits
mailing list