Kaydet (Commit) 907ffec4 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst aa273f05
#include<iostream>
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* /*
* This file is part of the LibreOffice project. * This file is part of the LibreOffice project.
...@@ -47,8 +46,10 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -47,8 +46,10 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
if (sub->getType()->isBooleanType()) { if (sub->getType()->isBooleanType()) {
return true; return true;
} }
IntegerLiteral const * lit = dyn_cast<IntegerLiteral>(sub); APSInt res;
if (lit != nullptr && lit->getValue().getLimitedValue() <= 1) { if (sub->isIntegerConstantExpr(res, compiler.getASTContext())
&& res.getLimitedValue() <= 1)
{
SourceLocation loc { sub->getLocStart() }; SourceLocation loc { sub->getLocStart() };
while (compiler.getSourceManager().isMacroArgExpansion(loc)) { while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
...@@ -66,7 +67,6 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -66,7 +67,6 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
return true; return true;
} }
} }
} }
if (isa<StringLiteral>(sub)) { if (isa<StringLiteral>(sub)) {
SourceLocation loc { sub->getLocStart() }; SourceLocation loc { sub->getLocStart() };
...@@ -136,19 +136,14 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -136,19 +136,14 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
<< expr->getCastKindName() << expr->getSubExpr()->getType() << expr->getCastKindName() << expr->getSubExpr()->getType()
<< expr->getType() << expr->getSourceRange(); << expr->getType() << expr->getSourceRange();
#endif #endif
} else if (sub->isIntegerConstantExpr(compiler.getASTContext())) { } else if (sub->isIntegerConstantExpr(res, compiler.getASTContext())) {
CallExpr const * ce = dyn_cast<CallExpr>(sub); report(
if (ce == nullptr DiagnosticsEngine::Warning,
|| compat::getBuiltinCallee(*ce) != Builtin::BI__builtin_expect) ("implicit conversion (%0) of integer constant expression of type"
{ " %1 with value %2 to %3"),
report( expr->getLocStart())
DiagnosticsEngine::Warning, << expr->getCastKindName() << expr->getSubExpr()->getType()
("implicit conversion (%0) of integer constant expression of" << res.toString(10) << expr->getType() << expr->getSourceRange();
" type %1 to %2"),
expr->getLocStart())
<< expr->getCastKindName() << expr->getSubExpr()->getType()
<< expr->getType() << expr->getSourceRange();
}
} }
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment