[cfe-commits] r113128 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGen/fold-const-declref.c

Eli Friedman eli.friedman at gmail.com
Sun Sep 5 17:10:32 PDT 2010


Author: efriedma
Date: Sun Sep  5 19:10:32 2010
New Revision: 113128

URL: http://llvm.org/viewvc/llvm-project?rev=113128&view=rev
Log:
PR7242: Make sure to use a different context for evaluating constant
initializers, so the result of the evaluation doesn't leak through
inconsistently.  Also, don't evaluate references to variables with
initializers with side-effects.


Added:
    cfe/trunk/test/CodeGen/fold-const-declref.c
Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=113128&r1=113127&r2=113128&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Sep  5 19:10:32 2010
@@ -1008,8 +1008,11 @@
 
         VD->setEvaluatingValue();
 
-        if (Visit(const_cast<Expr*>(Init))) {
+        Expr::EvalResult EResult;
+        if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects &&
+            EResult.Val.isInt()) {
           // Cache the evaluated value in the variable declaration.
+          Result = EResult.Val;
           VD->setEvaluatedValue(Result);
           return true;
         }

Added: cfe/trunk/test/CodeGen/fold-const-declref.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/fold-const-declref.c?rev=113128&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/fold-const-declref.c (added)
+++ cfe/trunk/test/CodeGen/fold-const-declref.c Sun Sep  5 19:10:32 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -emit-llvm-only
+
+// PR7242: Check that this doesn't crash.
+int main(void)
+{
+  int __negative = 1;
+  const int __max = __negative && 0 ;
+  __max / 0;
+}





More information about the cfe-commits mailing list