]> granicus.if.org Git - clang/commitdiff
Avoid assert-crash in a case where the expression passed to EmitConstantExpr
authorEli Friedman <eli.friedman@gmail.com>
Sat, 14 Nov 2009 08:51:33 +0000 (08:51 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 14 Nov 2009 08:51:33 +0000 (08:51 +0000)
legitimately has side-effects (and needs to be generated as a non-constant).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/static-init-2.cpp [new file with mode: 0644]

index b80a9416f56f614f1b2aff59ee588ee806ef4cce..40b845dba050394989df08b5dd5f96fcc6e1803d 100644 (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.");
diff --git a/test/CodeGenCXX/static-init-2.cpp b/test/CodeGenCXX/static-init-2.cpp
new file mode 100644 (file)
index 0000000..e229dd4
--- /dev/null
@@ -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;