summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy')
-rw-r--r--clang-tools-extra/clang-tidy/misc/AssertSideEffectCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp11
2 files changed, 13 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/misc/AssertSideEffectCheck.cpp
index 9d21b499ee9..fa589a4c759 100644
--- a/clang-tools-extra/clang-tidy/misc/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/AssertSideEffectCheck.cpp
@@ -55,9 +55,13 @@ AST_MATCHER_P(Expr, hasSideEffect, bool, CheckFunctionCalls) {
if (const auto *CExpr = dyn_cast<CallExpr>(E)) {
bool Result = CheckFunctionCalls;
- if (const auto *FuncDecl = CExpr->getDirectCallee())
- if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl))
+ if (const auto *FuncDecl = CExpr->getDirectCallee()) {
+ if (FuncDecl->getDeclName().isIdentifier() &&
+ FuncDecl->getName() == "__builtin_expect") // exceptions come here
+ Result = false;
+ else if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl))
Result &= !MethodDecl->isConst();
+ }
return Result;
}
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index ed9367c8a21..1b6b8971c88 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -41,15 +41,18 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
IsAlwaysFalse);
auto NonConstexprFunctionCall =
callExpr(hasDeclaration(functionDecl(unless(isConstexpr()))));
- auto Condition = expr(anyOf(
+ auto AssertCondition = expr(anyOf(
expr(ignoringParenCasts(anyOf(
AssertExprRoot,
unaryOperator(hasUnaryOperand(ignoringParenCasts(AssertExprRoot)))))),
- anything()), unless(findAll(NonConstexprFunctionCall)));
+ anything()), unless(findAll(NonConstexprFunctionCall))).bind("condition");
+ auto Condition = anyOf(ignoringParenImpCasts(callExpr(
+ hasDeclaration(functionDecl(hasName("__builtin_expect"))),
+ hasArgument(0, AssertCondition))), AssertCondition);
Finder->addMatcher(
- stmt(anyOf(conditionalOperator(hasCondition(Condition.bind("condition"))),
- ifStmt(hasCondition(Condition.bind("condition")))),
+ stmt(anyOf(conditionalOperator(hasCondition(Condition)),
+ ifStmt(hasCondition(Condition))),
unless(isInTemplateInstantiation())).bind("condStmt"),
this);
}
OpenPOWER on IntegriCloud