summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-02-25 19:03:12 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-02-25 19:05:01 +0100
commit907ffec4907eac13bfe51c98d4f27b433b7bb36f (patch)
tree6bb00d12e00ec9df50c455dbdb914589570e206b /compilerplugins
parentaa273f05776ff6bb8e1f96d1cc3baf40a997da0e (diff)
isIntegerConstantExpr is more general than IntegerLiteral
...and subsumes not only the use of __builtin_expect in assert, but also the use of __builtin_constant_p (nested) in htonl on Mac OS X. Change-Id: I62ab6c71c42948c4ec1e2f1e1d23223cbb13416b
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/literaltoboolconversion.cxx29
1 files changed, 12 insertions, 17 deletions
diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index bbb0cbf76973..5c87f474ec23 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -1,4 +1,3 @@
-#include<iostream>
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
@@ -47,8 +46,10 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
if (sub->getType()->isBooleanType()) {
return true;
}
- IntegerLiteral const * lit = dyn_cast<IntegerLiteral>(sub);
- if (lit != nullptr && lit->getValue().getLimitedValue() <= 1) {
+ APSInt res;
+ if (sub->isIntegerConstantExpr(res, compiler.getASTContext())
+ && res.getLimitedValue() <= 1)
+ {
SourceLocation loc { sub->getLocStart() };
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
@@ -66,7 +67,6 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
return true;
}
}
-
}
if (isa<StringLiteral>(sub)) {
SourceLocation loc { sub->getLocStart() };
@@ -136,19 +136,14 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
<< expr->getCastKindName() << expr->getSubExpr()->getType()
<< expr->getType() << expr->getSourceRange();
#endif
- } else if (sub->isIntegerConstantExpr(compiler.getASTContext())) {
- CallExpr const * ce = dyn_cast<CallExpr>(sub);
- if (ce == nullptr
- || compat::getBuiltinCallee(*ce) != Builtin::BI__builtin_expect)
- {
- report(
- DiagnosticsEngine::Warning,
- ("implicit conversion (%0) of integer constant expression of"
- " type %1 to %2"),
- expr->getLocStart())
- << expr->getCastKindName() << expr->getSubExpr()->getType()
- << expr->getType() << expr->getSourceRange();
- }
+ } else if (sub->isIntegerConstantExpr(res, compiler.getASTContext())) {
+ report(
+ DiagnosticsEngine::Warning,
+ ("implicit conversion (%0) of integer constant expression of type"
+ " %1 with value %2 to %3"),
+ expr->getLocStart())
+ << expr->getCastKindName() << expr->getSubExpr()->getType()
+ << res.toString(10) << expr->getType() << expr->getSourceRange();
}
return true;
}