summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-05-02 23:21:28 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-05-02 23:21:28 +0000
commitf7d3048e5b90c9d71ea462a721efce360260fd60 (patch)
treedaf1bb0cff12f6348f8a3e93f2385e0e0978220b /clang/lib/AST/ExprConstant.cpp
parent3af3900ee7f95c0617068b7778ce3f7fed81bbcc (diff)
downloadbcm5719-llvm-f7d3048e5b90c9d71ea462a721efce360260fd60.tar.gz
bcm5719-llvm-f7d3048e5b90c9d71ea462a721efce360260fd60.zip
Fix -Wunsequenced false-positives in code controlled by a branch on
__builtin_constant_p. If the operand of __builtin_constant_p is not constant and has side-effects, then code controlled by a branch on it is unreachable and we should not emit runtime behavior warnings in such code. llvm-svn: 359844
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 24b28971af3..8386ce8f2d4 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8269,11 +8269,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
case Builtin::BI__builtin_constant_p: {
const Expr *Arg = E->getArg(0);
- if (EvaluateBuiltinConstantP(Info, Arg))
+ if (EvaluateBuiltinConstantP(Info, Arg)) {
return Success(true, E);
- else if (Info.InConstantContext)
+ } else if (Info.InConstantContext || Arg->HasSideEffects(Info.Ctx)) {
+ // Outside a constant context, eagerly evaluate to false in the presence
+ // of side-effects in order to avoid -Wunsequenced false-positives in
+ // a branch on __builtin_constant_p(expr).
return Success(false, E);
- else {
+ } else {
Info.FFDiag(E, diag::note_invalid_subexpr_in_const_expr);
return false;
}
OpenPOWER on IntegriCloud