Special handling of __builtin_expect in boolean expressions

...as found in Mac OS X' assert macro definition,

  __builtin_expect(!(e), 0) ? ... : ...

with type

  long __builtin_expect(long, long)

The code in literaltoboolconversion.cxx is needed for

  assert(false);

Change-Id: I42f87482c56986af74b2ec849db9852f74c7c938
This commit is contained in:
Stephan Bergmann
2014-02-21 23:42:46 +01:00
parent 3316202888
commit 216bcceee1
2 changed files with 16 additions and 8 deletions

View File

@@ -192,7 +192,9 @@ bool ImplicitBoolConversion::TraverseCallExpr(CallExpr * expr) {
&& !(compat::getParamType(*t, n)->isSpecificBuiltinType(
BuiltinType::Int)
|| (compat::getParamType(*t, n)->isSpecificBuiltinType(
BuiltinType::UInt))))
BuiltinType::UInt))
|| (compat::getParamType(*t, n)->isSpecificBuiltinType(
BuiltinType::Long))))
{
reportWarning(i);
}

View File

@@ -1,3 +1,4 @@
#include<iostream>
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
@@ -135,13 +136,18 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
<< expr->getType() << expr->getSourceRange();
#endif
} else if (sub->isIntegerConstantExpr(compiler.getASTContext())) {
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();
CallExpr const * ce = dyn_cast<CallExpr>(sub);
if (ce == nullptr
|| ce->getBuiltinCallee() != 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();
}
}
return true;
}