[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
Wed Jun 3 03:15:46 PDT 2020


njames93 updated this revision to Diff 268116.
njames93 added a comment.

Included more builtins.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80887/new/

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,60 @@
 
 const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;
 
+static constexpr StringRef AllowedVariadics[] = {
+    // Disable formatting to prevent squashing the list.
+    // clang-format off
+    "__builtin_isgreater", 
+    "__builtin_isgreaterequal", 
+    "__builtin_isless",
+    "__builtin_islessequal", 
+    "__builtin_islessgreater", 
+    "__builtin_isunordered",
+    "__builtin_fpclassify", 
+    "__builtin_isfinite", 
+    "__builtin_isinf",
+    "__builtin_isinf_sign", 
+    "__builtin_isnan", 
+    "__builtin_isnormal",
+    "__builtin_signbit", 
+    "__builtin_constant_p", 
+    "__builtin_classify_type",
+    // "__builtin_va_start",
+    // "__builtin_stdarg_start",
+    "__builtin_assume_aligned", // Documented as variadic to support overloading
+    // "__builtin_fprintf",
+    // "__builtin_printf",
+    // "__builtin_snprintf",
+    // "__builtin___snprintf_chk",
+    // "__builtin___sprintf_chk",
+    // "__builtin___fprintf_chk",
+    // "__builtin___printf_chk",
+    "__builtin_prefetch",      // Documented as variadic to support overloading
+    "__builtin_shufflevector", // Documented as variadic but with a defined
+                               // number of args based on vector size.
+    "__builtin_convertvector", 
+    "__builtin_call_with_static_chain",
+    "__builtin_annotation", 
+    "__builtin_add_overflow", 
+    "__builtin_sub_overflow",
+    "__builtin_mul_overflow", 
+    "__builtin_preserve_access_index",
+    "__builtin_nontemporal_store", 
+    "__builtin_nontemporal_load",
+    // "__builtin_os_log_format_buffer_size",
+    // "__builtin_os_log_format",
+    // "__builtin_ms_va_start",
+    // clang-format on
+};
+
 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.268116.patch
Type: text/x-patch
Size: 3180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200603/a89afa66/attachment-0001.bin>


More information about the cfe-commits mailing list