Avoid assert-crash in a case where the expression passed to EmitConstantExpr

legitimately has side-effects (and needs to be generated as a non-constant).

llvm-svn: 88767
This commit is contained in:
Eli Friedman 2009-11-14 08:51:33 +00:00
parent b210fc598f
commit 274ab904d0
2 changed files with 7 additions and 3 deletions

View File

@ -821,9 +821,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
else
Success = E->Evaluate(Result, Context);
if (Success) {
assert(!Result.HasSideEffects &&
"Constant expr should not have any side effects!");
if (Success && !Result.HasSideEffects) {
switch (Result.Val.getKind()) {
case APValue::Uninitialized:
assert(0 && "Constant expressions should be initialized.");

View File

@ -0,0 +1,6 @@
// RUN: clang-cc -emit-llvm-only -verify %s
// Make sure we don't crash generating y; its value is constant, but the
// initializer has side effects, so EmitConstantExpr should fail.
int x();
int y = x() && 0;