[clang] Revert "[clang] Suppress -Wuninitialized for unevaluated builtin args" (#217816) (PR #246206)
Matt Turner via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 25 17:18:57 PST 2026
https://github.com/mattst88 created https://github.com/llvm/llvm-project/pull/246206
This reverts commit f19973fdd2fe4c112e0d659b9da21e2bb5a048f6.
Leaving the argument of __builtin_constant_p out of the CFG means
warnings in it that are queued with DiagRuntimeBehavior are no longer
dropped when they are in a branch that folds away. This breaks
-Werror builds of the Linux kernel, whose ilog2() has such a branch
inside MAYBE_BUILD_BUG_ON's __builtin_constant_p:
mm/hugetlb.c:4292:42: error: implicit conversion from 'unsigned long
long' to 'u32' (aka 'unsigned int') changes value from 17179869184
to 0 [-Werror,-Wconstant-conversion]
Reduced:
int f(unsigned char);
int g(void) { return __builtin_constant_p(0 ? f(65535) : 1); }
A fix is in review in #245821. Revert until it lands.
Reported in https://github.com/llvm/llvm-project/pull/217816#issuecomment-7145098249
>From f53c6381001fd7bdd8132e561f198feadde9ea5d Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Wed, 25 Nov 2026 20:16:24 -0500
Subject: [PATCH] Revert "[clang] Suppress -Wuninitialized for unevaluated
builtin args" (#217816)
This reverts commit f19973fdd2fe4c112e0d659b9da21e2bb5a048f6.
Leaving the argument of __builtin_constant_p out of the CFG means
warnings in it that are queued with DiagRuntimeBehavior are no longer
dropped when they are in a branch that folds away. This breaks
-Werror builds of the Linux kernel, whose ilog2() has such a branch
inside MAYBE_BUILD_BUG_ON's __builtin_constant_p:
mm/hugetlb.c:4292:42: error: implicit conversion from 'unsigned long
long' to 'u32' (aka 'unsigned int') changes value from 17179869184
to 0 [-Werror,-Wconstant-conversion]
Reduced:
int f(unsigned char);
int g(void) { return __builtin_constant_p(0 ? f(65535) : 1); }
A fix is in review in #245821. Revert until it lands.
Reported in https://github.com/llvm/llvm-project/pull/217816#issuecomment-7145098249
---
clang/docs/ReleaseNotes.md | 5 -----
clang/lib/Analysis/CFG.cpp | 3 ++-
clang/test/Analysis/cfg.cpp | 19 -------------------
clang/test/Sema/uninit-variables.c | 21 ---------------------
4 files changed, 2 insertions(+), 46 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index e461d4159098fb..b2566a0b5d09c2 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -615,11 +615,6 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
`-pedantic` or when that group is enabled explicitly, matching how the `_BitInt`
type itself is already handled.
-- `-Wuninitialized` no longer warns about an uninitialized variable passed to
- `__builtin_classify_type`, `__builtin_constant_p`,
- `__builtin_infer_alloc_token` or `__builtin_os_log_format_buffer_size`,
- none of which depends on its arguments' values.
-
- Fixed bug in `-Wdocumentation` so that it correctly handles explicit
function template instantiations (#64087).
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 59fed4d2432da3..6025cf202fb1f1 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -2886,7 +2886,8 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) {
if (FD->hasAttr<NoThrowAttr>())
AddEHEdge = false;
if (isBuiltinAssumeWithSideEffects(FD->getASTContext(), C) ||
- C->isUnevaluatedBuiltinCall(*Context))
+ FD->getBuiltinID() == Builtin::BI__builtin_object_size ||
+ FD->getBuiltinID() == Builtin::BI__builtin_dynamic_object_size)
OmitArguments = true;
}
diff --git a/clang/test/Analysis/cfg.cpp b/clang/test/Analysis/cfg.cpp
index dd0a8d5853e4ac..478e457d5dcd40 100644
--- a/clang/test/Analysis/cfg.cpp
+++ b/clang/test/Analysis/cfg.cpp
@@ -82,25 +82,6 @@ void testBuiltinSize() {
(void)__builtin_object_size(dummy(), 0);
}
-// CHECK-LABEL: void testBuiltinConstantP()
-// CHECK-NEXT: [B2 (ENTRY)]
-// CHECK-NEXT: Succs (1): B1
-// CHECK-EMPTY:
-// CHECK-NEXT: [B1]
-// CHECK-NEXT: 1: __builtin_constant_p
-// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, BuiltinFnToFnPtr, int (*)(...) noexcept)
-// CHECK-NEXT: 3: [B1.2](dummy())
-// CHECK-NEXT: 4: (void)[B1.3] (CStyleCastExpr, ToVoid, void)
-// CHECK-NEXT: Preds (1): B2
-// CHECK-NEXT: Succs (1): B0
-// CHECK-EMPTY:
-// CHECK-NEXT: [B0 (EXIT)]
-// CHECK-NEXT: Preds (1): B1
-void testBuiltinConstantP() {
- extern int *dummy();
- (void)__builtin_constant_p(dummy());
-}
-
class A {
public:
A() {}
diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c
index 55bc26d4e73a00..17e83de5f489ab 100644
--- a/clang/test/Sema/uninit-variables.c
+++ b/clang/test/Sema/uninit-variables.c
@@ -583,24 +583,3 @@ void aggregate() {
(void)sizeof({ struct with_explicit_field a; a; }); // no warning -- unevaluated operand
}
-
-// These builtins never read their arguments' values. Each uses its own
-// variable because only the first use of a variable is diagnosed, and
-// infer_alloc_token gets an expression because a bare variable is not read
-// there even when the argument is evaluated.
-int unevaluated_builtin_args(void) {
- int a, b, c;
- char *p, *q;
- int classify = __builtin_classify_type(a); // no-warning
- int constant = __builtin_constant_p(b); // no-warning
- __SIZE_TYPE__ size = __builtin_object_size(p, 0); // no-warning
- __SIZE_TYPE__ dsize = __builtin_dynamic_object_size(q, 0); // no-warning
- __SIZE_TYPE__ token = __builtin_infer_alloc_token(sizeof(int) * c); // no-warning
- return classify + constant + (int)size + (int)dsize + (int)token;
-}
-
-// __builtin_os_log_format, not this size query, evaluates the arguments.
-__SIZE_TYPE__ unevaluated_os_log_buffer_size(void) {
- int x;
- return __builtin_os_log_format_buffer_size("%d", x); // no-warning
-}
More information about the cfe-commits
mailing list