]> granicus.if.org Git - clang/commitdiff
Teach HasSideEffect about InitListExprs. Not having
authorChris Lattner <sabre@nondot.org>
Tue, 13 Apr 2010 17:34:23 +0000 (17:34 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 13 Apr 2010 17:34:23 +0000 (17:34 +0000)
this caused us to codegen dead globals like this:

struct foo { int a; int b; };

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

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

lib/AST/ExprConstant.cpp

index eeeeb5c836b815052e5271ac49166bd6364f04b5..c9aff6408fa940c7e2178cfe2a56fd0303ca1c03 100644 (file)
@@ -203,6 +203,13 @@ public:
     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