Author: puneeth_aditya_5656
Date: 2026-02-04T21:02:05+08:00
New Revision: 5b073761448229fd8f967f07517a35568e449aca

URL: 
https://github.com/llvm/llvm-project/commit/5b073761448229fd8f967f07517a35568e449aca
DIFF: 
https://github.com/llvm/llvm-project/commit/5b073761448229fd8f967f07517a35568e449aca.diff

LOG: [clang-tidy] Allow type-generic builtins in pro-type-vararg check (#178656)

## Summary
Add type generic builtins to the allowed variadics list in the
`cppcoreguidelines-pro-type-vararg` check (also used by `hicpp-vararg`):
- `__builtin_clzg`
- `__builtin_ctzg`
- `__builtin_popcountg`
- `__builtin_bswapg`

## Root Cause
These builtins are declared as variadic (`int(...)`) to accept any
integer type via `CustomTypeChecking`. However, they are not C style
vararg functions , they take exactly one argument of a generic integer
type.

## Test
Added test cases in `pro-type-vararg.cpp` to verify no warning is
emitted.

Fixes #178629

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
    clang-tools-extra/docs/ReleaseNotes.rst
    
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
index d5ff4af84b0b7..daa9f983b7886 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -178,6 +178,16 @@ 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.
+    // TODO: Remove some of the entries from the `AllowedVariadics` list.
+    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 ea80502735ede..0ad69f5fdc5aa 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -158,6 +158,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


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to