summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-11-15 11:24:24 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-11-15 14:38:27 +0100
commit82e1697d29fc783905a71278d36cec1d07e134a3 (patch)
treecb09375843c907b61ccf090e8b178853c4822c00 /compilerplugins
parent17d896731b5ee13ff3499d0db94315a67a9782a4 (diff)
Fix loplugin:consttobool for assert on macOS
...which internally uses __builtin_expect and thus caused > core/include/com/sun/star/uno/Any.hxx:750:13: error: implicit conversion of constant 1 of type 'long' to 'bool'; use 'true' instead [loplugin:consttobool] > assert(false); // this cannot happen > ^~~~~~~~~~~~~ > /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/assert.h:93:6: note: expanded from macro 'assert' > (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0) > ^~~~~~~~~~~~~~~~~~~~~~~~~ (See 216bcceee1ba908f617deb3f2404aff8085d5358 "Special handling of __builtin_expect in boolean expressions" for a similar fix in loplugin:literaltoboolconversion.) Change-Id: I4cf4b21006176c908995f5753dd0a38165383d87 Reviewed-on: https://gerrit.libreoffice.org/82773 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/consttobool.cxx9
1 files changed, 9 insertions, 0 deletions
diff --git a/compilerplugins/clang/consttobool.cxx b/compilerplugins/clang/consttobool.cxx
index 21fde3f547b1..a3c57d704b26 100644
--- a/compilerplugins/clang/consttobool.cxx
+++ b/compilerplugins/clang/consttobool.cxx
@@ -190,6 +190,15 @@ public:
return true;
}
}
+ if (auto const e = dyn_cast<CallExpr>(sub->IgnoreParenImpCasts()))
+ {
+ // Ignore use of `long __builtin_expect(long, long)`, as found in the definition of
+ // `assert` on macOS:
+ if (e->getBuiltinCallee() == Builtin::BI__builtin_expect)
+ {
+ return true;
+ }
+ }
bool suggestion;
bool replacement = {};
if (res.isInt())