<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It seems that this commit breaks the following bot<div class=""><a href="http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/12461/" class="">http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/12461/</a></div><div class=""><br class=""></div><div class="">Manman</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 21, 2015, at 1:09 PM, Matthias Gehre via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: mgehre<br class="">Date: Wed Oct 21 15:09:02 2015<br class="">New Revision: 250939<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=250939&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=250939&view=rev</a><br class="">Log:<br class="">[clang-tidy] add check cppcoreguidelines-pro-type-vararg<br class=""><br class="">Summary:<br class="">This check flags all calls to c-style vararg functions and all use<br class="">of va_list, va_start and va_arg.<br class=""><br class="">Passing to varargs assumes the correct type will be read. This is<br class="">fragile because it cannot generally be enforced to be safe in the<br class="">language and so relies on programmer discipline to get it right.<br class=""><br class="">This rule is part of the "Type safety" profile of the C++ Core<br class="">Guidelines, see<br class=""><a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type8-avoid-reading-from-varargs-or-passing-vararg-arguments-prefer-variadic-template-parameters-instead" class="">https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type8-avoid-reading-from-varargs-or-passing-vararg-arguments-prefer-variadic-template-parameters-instead</a><br class=""><br class="">This commits also reverts<br class="">  "[clang-tidy] add cert's VariadicFunctionDefCheck as cppcoreguidelines-pro-type-vararg-def"<br class="">because that check makes the SFINAE use of vararg functions impossible.<br class=""><br class="">Reviewers: alexfh, sbenza, bkramer, aaron.ballman<br class=""><br class="">Subscribers: cfe-commits<br class=""><br class="">Differential Revision: http://reviews.llvm.org/D13787<br class=""><br class="">Added:<br class="">    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp<br class="">    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h<br class="">    clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst<br class="">    clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp<br class="">Modified:<br class="">    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt<br class="">    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp<br class="">    clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br class=""><br class="">Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=250939&r1=250938&r2=250939&view=diff<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt (original)<br class="">+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Wed Oct 21 15:09:02 2015<br class="">@@ -7,6 +7,7 @@ add_clang_library(clangTidyCppCoreGuidel<br class="">   ProTypeReinterpretCastCheck.cpp<br class="">   ProTypeStaticCastDowncastCheck.cpp<br class="">   ProTypeUnionAccessCheck.cpp<br class="">+  ProTypeVarargCheck.cpp<br class=""><br class="">   LINK_LIBS<br class="">   clangAST<br class="">@@ -14,7 +15,6 @@ add_clang_library(clangTidyCppCoreGuidel<br class="">   clangBasic<br class="">   clangLex<br class="">   clangTidy<br class="">-  clangTidyCERTModule<br class="">   clangTidyMiscModule<br class="">   clangTidyUtils<br class="">   clangTooling<br class=""><br class="">Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=250939&r1=250938&r2=250939&view=diff<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (original)<br class="">+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp Wed Oct 21 15:09:02 2015<br class="">@@ -10,13 +10,13 @@<br class=""> #include "../ClangTidy.h"<br class=""> #include "../ClangTidyModule.h"<br class=""> #include "../ClangTidyModuleRegistry.h"<br class="">-#include "../cert/VariadicFunctionDefCheck.h"<br class=""> #include "../misc/AssignOperatorSignatureCheck.h"<br class=""> #include "ProBoundsPointerArithmeticCheck.h"<br class=""> #include "ProTypeConstCastCheck.h"<br class=""> #include "ProTypeReinterpretCastCheck.h"<br class=""> #include "ProTypeStaticCastDowncastCheck.h"<br class=""> #include "ProTypeUnionAccessCheck.h"<br class="">+#include "ProTypeVarargCheck.h"<br class=""><br class=""> namespace clang {<br class=""> namespace tidy {<br class="">@@ -30,14 +30,14 @@ public:<br class="">         "cppcoreguidelines-pro-bounds-pointer-arithmetic");<br class="">     CheckFactories.registerCheck<ProTypeConstCastCheck>(<br class="">         "cppcoreguidelines-pro-type-const-cast");<br class="">-    CheckFactories.registerCheck<VariadicFunctionDefCheck>(<br class="">-        "cppcoreguidelines-pro-type-vararg-def");<br class="">     CheckFactories.registerCheck<ProTypeReinterpretCastCheck>(<br class="">         "cppcoreguidelines-pro-type-reinterpret-cast");<br class="">     CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>(<br class="">         "cppcoreguidelines-pro-type-static-cast-downcast");<br class="">     CheckFactories.registerCheck<ProTypeUnionAccessCheck>(<br class="">         "cppcoreguidelines-pro-type-union-access");<br class="">+    CheckFactories.registerCheck<ProTypeVarargCheck>(<br class="">+        "cppcoreguidelines-pro-type-vararg");<br class="">     CheckFactories.registerCheck<misc::AssignOperatorSignatureCheck>(<br class="">         "cppcoreguidelines-c-copy-assignment-signature");<br class="">   }<br class=""><br class="">Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp?rev=250939&view=auto<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp (added)<br class="">+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp Wed Oct 21 15:09:02 2015<br class="">@@ -0,0 +1,76 @@<br class="">+//===--- ProTypeVarargCheck.cpp - clang-tidy-------------------------------===//<br class="">+//<br class="">+//                     The LLVM Compiler Infrastructure<br class="">+//<br class="">+// This file is distributed under the University of Illinois Open Source<br class="">+// License. See LICENSE.TXT for details.<br class="">+//<br class="">+//===----------------------------------------------------------------------===//<br class="">+<br class="">+#include "ProTypeVarargCheck.h"<br class="">+#include "clang/AST/ASTContext.h"<br class="">+#include "clang/ASTMatchers/ASTMatchFinder.h"<br class="">+<br class="">+using namespace clang::ast_matchers;<br class="">+<br class="">+namespace clang {<br class="">+namespace tidy {<br class="">+<br class="">+const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;<br class="">+<br class="">+void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {<br class="">+  if (!getLangOpts().CPlusPlus)<br class="">+    return;<br class="">+<br class="">+  Finder->addMatcher(vAArgExpr().bind("va_use"), this);<br class="">+<br class="">+  Finder->addMatcher(<br class="">+      callExpr(callee(functionDecl(isVariadic())))<br class="">+          .bind("callvararg"),<br class="">+      this);<br class="">+}<br class="">+<br class="">+static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {<br class="">+  const auto *FDecl = dyn_cast<FunctionDecl>(C->getCalleeDecl());<br class="">+  if (!FDecl)<br class="">+    return false;<br class="">+<br class="">+  auto N = FDecl->getNumParams(); // Number of parameters without '...'<br class="">+  if (C->getNumArgs() != N + 1)<br class="">+    return false; // more/less than one argument passed to '...'<br class="">+<br class="">+  const auto *IntLit =<br class="">+      dyn_cast<IntegerLiteral>(C->getArg(N)->IgnoreParenImpCasts());<br class="">+  if (!IntLit)<br class="">+    return false;<br class="">+<br class="">+  if (IntLit->getValue() != I)<br class="">+    return false;<br class="">+<br class="">+  return true;<br class="">+}<br class="">+<br class="">+void ProTypeVarargCheck::check(const MatchFinder::MatchResult &Result) {<br class="">+  if (const auto *Matched = Result.Nodes.getNodeAs<CallExpr>("callvararg")) {<br class="">+    if (hasSingleVariadicArgumentWithValue(Matched, 0))<br class="">+      return;<br class="">+    diag(Matched->getExprLoc(), "do not call c-style vararg functions");<br class="">+  }<br class="">+<br class="">+  if (const auto *Matched = Result.Nodes.getNodeAs<Expr>("va_use")) {<br class="">+    diag(Matched->getExprLoc(),<br class="">+         "do not use va_start/va_arg to define c-style vararg functions; "<br class="">+         "use variadic templates instead");<br class="">+  }<br class="">+<br class="">+  if (const auto *Matched = Result.Nodes.getNodeAs<VarDecl>("va_list")) {<br class="">+    auto SR = Matched->getSourceRange();<br class="">+    if (SR.isInvalid())<br class="">+      return; // some implicitly generated builtins take va_list<br class="">+    diag(SR.getBegin(), "do not declare variables of type va_list; "<br class="">+                        "use variadic templates instead");<br class="">+  }<br class="">+}<br class="">+<br class="">+} // namespace tidy<br class="">+} // namespace clang<br class=""><br class="">Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h?rev=250939&view=auto<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h (added)<br class="">+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h Wed Oct 21 15:09:02 2015<br class="">@@ -0,0 +1,34 @@<br class="">+//===--- ProTypeVarargCheck.h - clang-tidy--------------------*- C++ -*-===//<br class="">+//<br class="">+//                     The LLVM Compiler Infrastructure<br class="">+//<br class="">+// This file is distributed under the University of Illinois Open Source<br class="">+// License. See LICENSE.TXT for details.<br class="">+//<br class="">+//===----------------------------------------------------------------------===//<br class="">+<br class="">+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H<br class="">+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H<br class="">+<br class="">+#include "../ClangTidy.h"<br class="">+<br class="">+namespace clang {<br class="">+namespace tidy {<br class="">+<br class="">+/// This check flags all calls to c-style variadic functions and all use<br class="">+/// of va_arg.<br class="">+///<br class="">+/// For the user-facing documentation see:<br class="">+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.html<br class="">+class ProTypeVarargCheck : public ClangTidyCheck {<br class="">+public:<br class="">+  ProTypeVarargCheck(StringRef Name, ClangTidyContext *Context)<br class="">+      : ClangTidyCheck(Name, Context) {}<br class="">+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;<br class="">+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;<br class="">+};<br class="">+<br class="">+} // namespace tidy<br class="">+} // namespace clang<br class="">+<br class="">+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H<br class=""><br class="">Added: clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst?rev=250939&view=auto<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst (added)<br class="">+++ clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst Wed Oct 21 15:09:02 2015<br class="">@@ -0,0 +1,12 @@<br class="">+cppcoreguidelines-pro-type-vararg<br class="">+=====================================<br class="">+<br class="">+This check flags all calls to c-style vararg functions and all use<br class="">+of va_arg.<br class="">+To allow for SFINAE use of vararg functions, a call is not flagged if<br class="">+a literal 0 is passed as the only vararg argument.<br class="">+<br class="">+Passing to varargs assumes the correct type will be read. This is fragile because it cannot generally be enforced to be safe in the language and so relies on programmer discipline to get it right.<br class="">+<br class="">+This rule is part of the "Type safety" profile of the C++ Core Guidelines, see<br class="">+https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type8-avoid-reading-from-varargs-or-passing-vararg-arguments-prefer-variadic-template-parameters-instead<br class=""><br class="">Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=250939&r1=250938&r2=250939&view=diff<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)<br class="">+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Wed Oct 21 15:09:02 2015<br class="">@@ -9,6 +9,7 @@ List of clang-tidy Checks<br class="">    cppcoreguidelines-pro-type-reinterpret-cast<br class="">    cppcoreguidelines-pro-type-static-cast-downcast<br class="">    cppcoreguidelines-pro-type-union-access<br class="">+   cppcoreguidelines-pro-type-vararg<br class="">    google-build-explicit-make-pair<br class="">    google-build-namespaces<br class="">    google-build-using-namespace<br class=""><br class="">Added: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp?rev=250939&view=auto<br class="">==============================================================================<br class="">--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp (added)<br class="">+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp Wed Oct 21 15:09:02 2015<br class="">@@ -0,0 +1,51 @@<br class="">+// RUN: %python %S/check_clang_tidy.py %s cppcoreguidelines-pro-type-vararg %t<br class="">+<br class="">+void f(int i);<br class="">+void f_vararg(int i, ...);<br class="">+<br class="">+struct C {<br class="">+  void g_vararg(...);<br class="">+  void g(const char*);<br class="">+} c;<br class="">+<br class="">+template<typename... P><br class="">+void cpp_vararg(P... p);<br class="">+<br class="">+void check() {<br class="">+  f_vararg(1, 7, 9);<br class="">+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]<br class="">+  c.g_vararg("foo");<br class="">+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call c-style vararg functions<br class="">+<br class="">+  f(3); // OK<br class="">+  c.g("foo"); // OK<br class="">+  cpp_vararg(1, 7, 9); // OK<br class="">+}<br class="">+<br class="">+// ... as a parameter is allowed (e.g. for SFINAE)<br class="">+template <typename T><br class="">+void CallFooIfAvailableImpl(T& t, ...) {<br class="">+  // nothing<br class="">+}<br class="">+template <typename T><br class="">+void CallFooIfAvailableImpl(T& t, decltype(t.foo())*) {<br class="">+  t.foo();<br class="">+}<br class="">+template <typename T><br class="">+void CallFooIfAvailable(T& t) {<br class="">+  CallFooIfAvailableImpl(t, 0); // OK to call variadic function when the argument is a literal 0<br class="">+}<br class="">+<br class="">+#include <cstdarg><br class="">+void my_printf(const char* format, ...) {<br class="">+  va_list ap;<br class="">+  va_start(ap, format);<br class="">+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call c-style vararg functions<br class="">+  va_list n;<br class="">+  va_copy(n, ap); // Don't warn, va_copy is anyway useless without va_start<br class="">+  int i = va_arg(ap, int);<br class="">+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use va_start/va_arg to define c-style vararg functions; use variadic templates instead<br class="">+  va_end(ap); // Don't warn, va_end is anyway useless without va_start<br class="">+}<br class="">+<br class="">+int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list<br class=""><br class=""><br class="">_______________________________________________<br class="">cfe-commits mailing list<br class="">cfe-commits@lists.llvm.org<br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>