summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/literaltoboolconversion.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-02-21 23:42:46 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-02-21 23:47:23 +0100
commit216bcceee1ba908f617deb3f2404aff8085d5358 (patch)
tree1d8855f102be9f91ede2f6449859d1983d6c1b6e /compilerplugins/clang/literaltoboolconversion.cxx
parent3316202888f8849e26afe750cbb7db3087b9c416 (diff)
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
Diffstat (limited to 'compilerplugins/clang/literaltoboolconversion.cxx')
-rw-r--r--compilerplugins/clang/literaltoboolconversion.cxx20
1 files changed, 13 insertions, 7 deletions
diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index d156e9bba186..1bbdc0550194 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -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;
}