[PATCH] D80887: [clang-tidy] ignore builtin varargs from pro-type-vararg-check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 31 04:15:30 PDT 2020


njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, mgehre.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai.
Herald added a project: clang.

Disables the check from warning on some built in vararg functions, Address Clang-tidy should not consider __builtin_constant_p a variadic function. <https://bugs.llvm.org/show_bug.cgi?id=45860>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80887

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -49,3 +49,11 @@
 }
 
 int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list
+
+void ignoredBuiltinsTest() {
+  (void)__builtin_assume_aligned(0, 8);
+  (void)__builtin_constant_p(0);
+  (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
+  (void)__builtin_isinf_sign(0.f);
+  (void)__builtin_prefetch(nullptr);
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -18,11 +18,20 @@
 
 const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;
 
+// FIXME: Add any more builtin variadics that shouldn't trigger this
+static constexpr StringRef AllowedVariadics[] = {
+    "__builtin_constant_p", "__builtin_isinf_sign", "__builtin_assume_aligned",
+    "__builtin_prefetch",   "__builtin_fpclassify",
+};
+
 void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(vAArgExpr().bind("va_use"), this);
 
   Finder->addMatcher(
-      callExpr(callee(functionDecl(isVariadic()))).bind("callvararg"), this);
+      callExpr(callee(functionDecl(isVariadic(),
+                                   unless(hasAnyName(AllowedVariadics)))))
+          .bind("callvararg"),
+      this);
 }
 
 static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80887.267495.patch
Type: text/x-patch
Size: 1813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200531/d1fe2414/attachment.bin>


More information about the cfe-commits mailing list