steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96223

Files:
  clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
  clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h


Index: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
+++ clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
@@ -30,6 +30,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+    return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   SourceLocation getLastParenLoc(const ASTContext *ASTCtx,
Index: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -27,48 +27,40 @@
     : ClangTidyCheck(Name, Context) {}
 
 void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
-  auto NegatedString = unaryOperator(
-      hasOperatorName("!"), 
hasUnaryOperand(ignoringImpCasts(stringLiteral())));
+  auto NegatedString =
+      unaryOperator(hasOperatorName("!"), hasUnaryOperand(stringLiteral()));
   auto IsAlwaysFalse =
       expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)),
                  cxxNullPtrLiteralExpr(), gnuNullExpr(), NegatedString))
           .bind("isAlwaysFalse");
-  auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(
-      IsAlwaysFalse, cStyleCastExpr(has(ignoringParenImpCasts(IsAlwaysFalse)))
-                         .bind("castExpr")));
-  auto AssertExprRoot = anyOf(
-      binaryOperator(
-          hasAnyOperatorName("&&", "=="),
-          
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
-          anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
-                anything()))
-          .bind("assertExprRoot"),
-      IsAlwaysFalse);
+  auto IsAlwaysFalseWithCast =
+      anyOf(IsAlwaysFalse, 
cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"));
+  auto AssertExprRoot =
+      anyOf(binaryOperator(
+                hasAnyOperatorName("&&", "=="),
+                hasEitherOperand(stringLiteral().bind("assertMSG")),
+                anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
+                      anything()))
+                .bind("assertExprRoot"),
+            IsAlwaysFalse);
   auto NonConstexprFunctionCall =
       callExpr(hasDeclaration(functionDecl(unless(isConstexpr()))));
   auto AssertCondition =
-      expr(
-          anyOf(expr(ignoringParenCasts(anyOf(
-                    AssertExprRoot, unaryOperator(hasUnaryOperand(
-                                        
ignoringParenCasts(AssertExprRoot)))))),
-                anything()),
-          unless(findAll(NonConstexprFunctionCall)))
+      expr(anyOf(expr(anyOf(AssertExprRoot,
+                            unaryOperator(hasUnaryOperand(AssertExprRoot)))),
+                 anything()),
+           unless(findAll(NonConstexprFunctionCall)))
           .bind("condition");
   auto Condition =
-      anyOf(ignoringParenImpCasts(callExpr(
-                hasDeclaration(functionDecl(hasName("__builtin_expect"))),
-                hasArgument(0, AssertCondition))),
+      anyOf(callExpr(traverse(TK_AsIs, callExpr(hasDeclaration(functionDecl(
+                                           hasName("__builtin_expect"))))),
+                     hasArgument(0, AssertCondition)),
             AssertCondition);
 
-  Finder->addMatcher(conditionalOperator(hasCondition(Condition),
-                                         unless(isInTemplateInstantiation()))
-                         .bind("condStmt"),
-                     this);
-
   Finder->addMatcher(
-      ifStmt(hasCondition(Condition), unless(isInTemplateInstantiation()))
-          .bind("condStmt"),
-      this);
+      conditionalOperator(hasCondition(Condition)).bind("condStmt"), this);
+
+  Finder->addMatcher(ifStmt(hasCondition(Condition)).bind("condStmt"), this);
 }
 
 void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {


Index: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
+++ clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
@@ -30,6 +30,9 @@
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+    return TK_IgnoreUnlessSpelledInSource;
+  }
 
 private:
   SourceLocation getLastParenLoc(const ASTContext *ASTCtx,
Index: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -27,48 +27,40 @@
     : ClangTidyCheck(Name, Context) {}
 
 void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
-  auto NegatedString = unaryOperator(
-      hasOperatorName("!"), hasUnaryOperand(ignoringImpCasts(stringLiteral())));
+  auto NegatedString =
+      unaryOperator(hasOperatorName("!"), hasUnaryOperand(stringLiteral()));
   auto IsAlwaysFalse =
       expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)),
                  cxxNullPtrLiteralExpr(), gnuNullExpr(), NegatedString))
           .bind("isAlwaysFalse");
-  auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(
-      IsAlwaysFalse, cStyleCastExpr(has(ignoringParenImpCasts(IsAlwaysFalse)))
-                         .bind("castExpr")));
-  auto AssertExprRoot = anyOf(
-      binaryOperator(
-          hasAnyOperatorName("&&", "=="),
-          hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
-          anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
-                anything()))
-          .bind("assertExprRoot"),
-      IsAlwaysFalse);
+  auto IsAlwaysFalseWithCast =
+      anyOf(IsAlwaysFalse, cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"));
+  auto AssertExprRoot =
+      anyOf(binaryOperator(
+                hasAnyOperatorName("&&", "=="),
+                hasEitherOperand(stringLiteral().bind("assertMSG")),
+                anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
+                      anything()))
+                .bind("assertExprRoot"),
+            IsAlwaysFalse);
   auto NonConstexprFunctionCall =
       callExpr(hasDeclaration(functionDecl(unless(isConstexpr()))));
   auto AssertCondition =
-      expr(
-          anyOf(expr(ignoringParenCasts(anyOf(
-                    AssertExprRoot, unaryOperator(hasUnaryOperand(
-                                        ignoringParenCasts(AssertExprRoot)))))),
-                anything()),
-          unless(findAll(NonConstexprFunctionCall)))
+      expr(anyOf(expr(anyOf(AssertExprRoot,
+                            unaryOperator(hasUnaryOperand(AssertExprRoot)))),
+                 anything()),
+           unless(findAll(NonConstexprFunctionCall)))
           .bind("condition");
   auto Condition =
-      anyOf(ignoringParenImpCasts(callExpr(
-                hasDeclaration(functionDecl(hasName("__builtin_expect"))),
-                hasArgument(0, AssertCondition))),
+      anyOf(callExpr(traverse(TK_AsIs, callExpr(hasDeclaration(functionDecl(
+                                           hasName("__builtin_expect"))))),
+                     hasArgument(0, AssertCondition)),
             AssertCondition);
 
-  Finder->addMatcher(conditionalOperator(hasCondition(Condition),
-                                         unless(isInTemplateInstantiation()))
-                         .bind("condStmt"),
-                     this);
-
   Finder->addMatcher(
-      ifStmt(hasCondition(Condition), unless(isInTemplateInstantiation()))
-          .bind("condStmt"),
-      this);
+      conditionalOperator(hasCondition(Condition)).bind("condStmt"), this);
+
+  Finder->addMatcher(ifStmt(hasCondition(Condition)).bind("condStmt"), this);
 }
 
 void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to