From ee5872187571906c4430e181184142112742468c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 8 Jul 2014 15:41:20 +0000 Subject: [PATCH] [clang-tidy] Address review comments for the Twine checker. - Remove unused includes. - Minor wording fix. - Added support to check for clang-tidy messages to check_clang_tidy_fix.sh = Updated test case. llvm-svn: 212540 --- .../clang-tidy/llvm/TwineLocalCheck.cpp | 3 +-- clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h | 1 - .../test/clang-tidy/check_clang_tidy_fix.sh | 3 ++- .../test/clang-tidy/llvm-twine-local.cpp | 12 +++++------- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp index f30628e23b6f..bc255aaa35cd 100644 --- a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp @@ -11,7 +11,6 @@ #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Lex/Lexer.h" -#include "llvm/Support/raw_ostream.h" using namespace clang::ast_matchers; @@ -29,7 +28,7 @@ void TwineLocalCheck::registerMatchers(MatchFinder *Finder) { void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) { const VarDecl *VD = Result.Nodes.getNodeAs("variable"); auto Diag = diag(VD->getLocation(), - "twine variables are prone to use after free bugs"); + "twine variables are prone to use-after-free bugs"); // If this VarDecl has an initializer try to fix it. if (VD->hasInit()) { diff --git a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h index f538f81430c9..90320ed134fd 100644 --- a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h +++ b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h @@ -11,7 +11,6 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_TWINE_LOCAL_CHECK_H #include "../ClangTidy.h" -#include "llvm/Support/Regex.h" namespace clang { namespace tidy { diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy_fix.sh b/clang-tools-extra/test/clang-tidy/check_clang_tidy_fix.sh index c272db39292f..6ec73e222ce4 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy_fix.sh +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy_fix.sh @@ -7,5 +7,6 @@ CHECK_TO_RUN=$2 TEMPORARY_FILE=$3.cpp grep -Ev "// *[A-Z-]+:" ${INPUT_FILE} > ${TEMPORARY_FILE} -clang-tidy ${TEMPORARY_FILE} -fix --checks="-*,${CHECK_TO_RUN}" -- --std=c++11 +clang-tidy ${TEMPORARY_FILE} -fix --checks="-*,${CHECK_TO_RUN}" -- --std=c++11 > ${TEMPORARY_FILE}.msg 2>&1 FileCheck -input-file=${TEMPORARY_FILE} ${INPUT_FILE} -strict-whitespace +not grep CHECK-MESSAGES ${INPUT_FILE} || FileCheck -input-file=${TEMPORARY_FILE}.msg ${INPUT_FILE} -check-prefix=CHECK-MESSAGES diff --git a/clang-tools-extra/test/clang-tidy/llvm-twine-local.cpp b/clang-tools-extra/test/clang-tidy/llvm-twine-local.cpp index 0f134a5500a6..dc8f8f0cb07e 100644 --- a/clang-tools-extra/test/clang-tidy/llvm-twine-local.cpp +++ b/clang-tools-extra/test/clang-tidy/llvm-twine-local.cpp @@ -1,7 +1,5 @@ -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: clang-tidy %t.cpp -checks='-*,llvm-twine-local' -fix -- > %t.msg 2>&1 -// RUN: FileCheck -input-file=%t.cpp %s -// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s llvm-twine-local %t +// REQUIRES: shell namespace llvm { class Twine { @@ -17,19 +15,19 @@ using namespace llvm; void foo(const Twine &x); static Twine Moo = Twine("bark") + "bah"; -// CHECK-MASSAGES: twine variables are prone to use after free bugs +// CHECK-MASSAGES: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes // CHECK: static std::string Moo = (Twine("bark") + "bah").str(); int main() { const Twine t = Twine("a") + "b" + Twine(42); -// CHECK-MASSAGES: twine variables are prone to use after free bugs +// CHECK-MASSAGES: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes // CHECK: std::string t = (Twine("a") + "b" + Twine(42)).str(); foo(Twine("a") + "b"); Twine Prefix = false ? "__INT_FAST" : "__UINT_FAST"; -// CHECK-MASSAGES: twine variables are prone to use after free bugs +// CHECK-MASSAGES: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes // CHECK: const char * Prefix = false ? "__INT_FAST" : "__UINT_FAST"; }