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
This commit is contained in:
parent
3af3900ee7
commit
f7d3048e5b
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -93,4 +93,6 @@ void test() {
|
|||
_Generic(++a, default: 0) + ++a; // ok
|
||||
sizeof(++a) + ++a; // ok
|
||||
_Alignof(++a) + ++a; // expected-warning {{extension}}
|
||||
|
||||
__builtin_constant_p(f(++a, 0)) ? f(f(++a, 0), f(++a, 0)) : 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue