From a714469d026f56f25dd491f5ee4201b793255b2f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 23 Jul 2014 04:13:00 +0000 Subject: [PATCH] Revert r213647; the added test triggers an assertion. llvm-svn: 213722 --- clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 1 - .../clang-tidy/misc/MiscTidyModule.cpp | 4 -- clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp | 83 ---------------------- clang-tools-extra/clang-tidy/misc/UnusedRAII.h | 47 ------------ .../test/clang-tidy/misc-unused-raii.cpp | 61 ---------------- 5 files changed, 196 deletions(-) delete mode 100644 clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp delete mode 100644 clang-tools-extra/clang-tidy/misc/UnusedRAII.h delete mode 100644 clang-tools-extra/test/clang-tidy/misc-unused-raii.cpp diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 5614d12..aee8049 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -6,7 +6,6 @@ add_clang_library(clangTidyMiscModule MiscTidyModule.cpp RedundantSmartptrGet.cpp SwappedArgumentsCheck.cpp - UnusedRAII.cpp UseOverride.cpp LINK_LIBS diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index e3dbdc3..669ad08 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -14,7 +14,6 @@ #include "BoolPointerImplicitConversion.h" #include "RedundantSmartptrGet.h" #include "SwappedArgumentsCheck.h" -#include "UnusedRAII.h" #include "UseOverride.h" namespace clang { @@ -36,9 +35,6 @@ public: "misc-swapped-arguments", new ClangTidyCheckFactory()); CheckFactories.addCheckFactory( - "misc-unused-raii", - new ClangTidyCheckFactory()); - CheckFactories.addCheckFactory( "misc-use-override", new ClangTidyCheckFactory()); } diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp b/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp deleted file mode 100644 index 7f06a49..0000000 --- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.cpp +++ /dev/null @@ -1,83 +0,0 @@ -//===--- UnusedRAII.cpp - clang-tidy ---------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "UnusedRAII.h" -#include "clang/AST/ASTContext.h" -#include "clang/Lex/Lexer.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace ast_matchers { -AST_MATCHER(CXXRecordDecl, hasUserDeclaredDestructor) { - // TODO: If the dtor is there but empty we don't want to warn either. - return Node.hasUserDeclaredDestructor(); -} -} // namespace ast_matchers - -namespace tidy { - -void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) { - // Look for temporaries that are constructed in-place and immediately - // destroyed. Look for temporaries created by a functional cast but not for - // those returned from a call. - auto BindTemp = bindTemporaryExpr(unless(has(callExpr()))).bind("temp"); - Finder->addMatcher( - exprWithCleanups( - unless(hasAncestor(decl( - anyOf(recordDecl(ast_matchers::isTemplateInstantiation()), - functionDecl(ast_matchers::isTemplateInstantiation()))))), - hasParent(compoundStmt().bind("compound")), - hasDescendant(typeLoc().bind("typeloc")), - hasType(recordDecl(hasUserDeclaredDestructor())), - anyOf(has(BindTemp), has(functionalCastExpr(has(BindTemp))))) - .bind("expr"), - this); -} - -void UnusedRAIICheck::check(const MatchFinder::MatchResult &Result) { - const auto *E = Result.Nodes.getStmtAs("expr"); - - // We ignore code expanded from macros to reduce the number of false - // positives. - if (E->getLocStart().isMacroID()) - return; - - // Don't emit a warning for the last statement in the surrounding compund - // statement. - const auto *CS = Result.Nodes.getStmtAs("compound"); - if (E == CS->body_back()) - return; - - // Emit a warning. - auto D = diag(E->getLocStart(), "object destroyed immediately after " - "creation; did you mean to name the object?"); - const char *Replacement = " give_me_a_name"; - - // If this is a default ctor we have to remove the parens or we'll introduce a - // most vexing parse. - const auto *BTE = Result.Nodes.getStmtAs("temp"); - if (const auto *TOE = dyn_cast(BTE->getSubExpr())) - if (TOE->getNumArgs() == 0) { - D << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(TOE->getParenOrBraceRange()), - Replacement); - return; - } - - // Otherwise just suggest adding a name. - const auto *TL = Result.Nodes.getNodeAs("typeloc"); - D << FixItHint::CreateInsertion( - Lexer::getLocForEndOfToken(TL->getLocEnd(), 0, *Result.SourceManager, - Result.Context->getLangOpts()), - Replacement); -} - -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/UnusedRAII.h b/clang-tools-extra/clang-tidy/misc/UnusedRAII.h deleted file mode 100644 index 6850ab9..0000000 --- a/clang-tools-extra/clang-tidy/misc/UnusedRAII.h +++ /dev/null @@ -1,47 +0,0 @@ -//===--- UnusedRAII.h - clang-tidy ------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { - -/// \brief Finds temporaries that look like RAII objects. -/// -/// The canonical example for this is a scoped lock. -/// \code -/// { -/// scoped_lock(&global_mutex); -/// critical_section(); -/// } -/// \endcode -/// The destructor of the scoped_lock is called before the critical_section is -/// entered, leaving it unprotected. -/// -/// We apply a number of heuristics to reduce the false positive count of this -/// check: -/// - Ignore code expanded from macros. Testing frameworks make heavy use of -/// this. -/// - Ignore types with no user-declared constructor. Those are very unlikely -/// to be RAII objects. -/// - Ignore objects at the end of a compound statement (doesn't change behavior). -/// - Ignore objects returned from a call. -class UnusedRAIICheck : public ClangTidyCheck { -public: - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H diff --git a/clang-tools-extra/test/clang-tidy/misc-unused-raii.cpp b/clang-tools-extra/test/clang-tidy/misc-unused-raii.cpp deleted file mode 100644 index e32410f..0000000 --- a/clang-tools-extra/test/clang-tidy/misc-unused-raii.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-unused-raii %t -// REQUIRES: shell - -struct Foo { - Foo(); - Foo(int); - Foo(int, int); - ~Foo(); -}; - -struct Bar { - Bar(); - Foo f; -}; - -template -void qux() { - T(42); -} - -template -struct TFoo { - TFoo(T); - ~TFoo(); -}; - -Foo f(); - -struct Ctor { - Ctor(int); - Ctor() { - Ctor(0); // TODO: warn here. - } -}; - -void test() { - Foo(42); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object? -// CHECK-FIXES: Foo give_me_a_name(42); - Foo(23, 42); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object? -// CHECK-FIXES: Foo give_me_a_name(23, 42); - Foo(); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object? -// CHECK-FIXES: Foo give_me_a_name; - TFoo(23); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object? -// CHECK-FIXES: TFoo give_me_a_name(23); - - Bar(); - f(); - qux(); - -#define M Foo(); - M - - { - Foo(); - } - Foo(); -} -- 2.7.4