[cfe-commits] r101150 - /cfe/trunk/lib/AST/ExprConstant.cpp

Chris Lattner sabre at nondot.org
Tue Apr 13 10:34:23 PDT 2010


Author: lattner
Date: Tue Apr 13 12:34:23 2010
New Revision: 101150

URL: http://llvm.org/viewvc/llvm-project?rev=101150&view=rev
Log:
Teach HasSideEffect about InitListExprs.  Not having
this caused us to codegen dead globals like this:

struct foo { int a; int b; };

static struct foo fooarray[] = {
  {1, 2},
  {4},
};


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=101150&r1=101149&r2=101150&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Apr 13 12:34:23 2010
@@ -203,6 +203,13 @@
     return Visit(E->getSubExpr());
   }
   bool VisitUnaryOperator(UnaryOperator *E) { return Visit(E->getSubExpr()); }
+    
+  // Has side effects if any element does.
+  bool VisitInitListExpr(InitListExpr *E) {
+    for (unsigned i = 0, e = E->getNumInits(); i != e; ++i)
+      if (Visit(E->getInit(i))) return true;
+    return false;
+  }
 };
 
 } // end anonymous namespace





More information about the cfe-commits mailing list