[clang-tools-extra] [clang-tidy] Allow type-generic builtins in pro-type-vararg check (PR #178656)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 31 05:39:39 PST 2026
https://github.com/mugiwaraluffy56 updated https://github.com/llvm/llvm-project/pull/178656
>From 5227669582c0704743b2b6d3ea10f062272dfcc1 Mon Sep 17 00:00:00 2001
From: mugiwaraluffy56 <myakampuneeth at gmail.com>
Date: Thu, 29 Jan 2026 19:22:00 +0530
Subject: [PATCH] [clang-tidy] Allow type-generic builtins in pro-type-vararg
check
Add __builtin_clzg, __builtin_ctzg, __builtin_popcountg, and
__builtin_bswapg to the allowed variadics list. These type-generic
builtins are declared as variadic to accept any integer type, but
they are not C-style vararg functions and should not trigger the
hicpp-vararg / cppcoreguidelines-pro-type-vararg warning.
Fixes #178629
---
.../clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp | 9 +++++++++
clang-tools-extra/docs/ReleaseNotes.rst | 6 ++++++
.../checkers/cppcoreguidelines/pro-type-vararg.cpp | 6 ++++++
3 files changed, 21 insertions(+)
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
index d5ff4af84b0b7..7c4286d410d36 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -178,6 +178,15 @@ void ProTypeVarargCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Matched = Result.Nodes.getNodeAs<CallExpr>("callvararg")) {
if (hasSingleVariadicArgumentWithValue(Matched, 0))
return;
+
+ // Skip builtins with custom type checking - they use variadics as an
+ // implementation detail to accept multiple types, not for C-style varargs.
+ if (const auto *FD = Matched->getDirectCallee())
+ if (const unsigned BuiltinID = FD->getBuiltinID();
+ BuiltinID &&
+ Result.Context->BuiltinInfo.hasCustomTypechecking(BuiltinID))
+ return;
+
diag(Matched->getExprLoc(), "do not call c-style vararg functions");
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 754880bd1a381..082117452b2ff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -136,6 +136,12 @@ Changes in existing checks
the invalidating function in the warning message when a custom invalidation
function is used (via the `InvalidationFunctions` option).
+- Improved :doc:`cppcoreguidelines-pro-type-vararg
+ <clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check by no longer
+ warning on builtins with custom type checking (e.g., type-generic builtins
+ like ``__builtin_clzg``) that use variadic declarations as an implementation
+ detail.
+
- Improved :doc:`llvm-use-ranges
<clang-tidy/checks/llvm/use-ranges>` check by adding support for the following
algorithms: ``std::accumulate``, ``std::replace_copy``, and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
index 3f73d1de333f4..1a5a5fb7dd93c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
@@ -57,6 +57,12 @@ void ignoredBuiltinsTest(void *ptr) {
(void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
(void)__builtin_isinf_sign(0.f);
(void)__builtin_prefetch(nullptr);
+
+ // GH#178629: Type-generic builtins should not warn.
+ (void)__builtin_clzg(1u);
+ (void)__builtin_ctzg(1u);
+ (void)__builtin_popcountg(1u);
+ (void)__builtin_bswapg(1u);
}
// Some implementations of __builtin_va_list and __builtin_ms_va_list desugared
More information about the cfe-commits
mailing list