[llvm-commits] [llvm] r129207 - in /llvm/trunk: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll
Eli Friedman
eli.friedman at gmail.com
Sat Apr 9 02:11:09 PDT 2011
Author: efriedma
Date: Sat Apr 9 04:11:09 2011
New Revision: 129207
URL: http://llvm.org/viewvc/llvm-project?rev=129207&view=rev
Log:
Add back a couple checks removed by r129128; the fact that an intitializer
is an array of structures doesn't imply it's a ConstantArray of
ConstantStruct.
Added:
llvm/trunk/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=129207&r1=129206&r2=129207&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sat Apr 9 04:11:09 2011
@@ -1954,11 +1954,13 @@
// only allowed to optimize the initializer if it is unique.
if (!GV->hasUniqueInitializer()) return 0;
- ConstantArray *CA = cast<ConstantArray>(GV->getInitializer());
-
+ ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
+ if (!CA) return 0;
+
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) {
- ConstantStruct *CS = cast<ConstantStruct>(*i);
-
+ ConstantStruct *CS = dyn_cast<ConstantStruct>(*i);
+ if (!CS) return 0;
+
if (isa<ConstantPointerNull>(CS->getOperand(1)))
continue;
Added: llvm/trunk/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll?rev=129207&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll Sat Apr 9 04:11:09 2011
@@ -0,0 +1,5 @@
+; RUN: opt < %s -globalopt -disable-output
+
+%0 = type { i32, void ()* }
+ at llvm.global_ctors = appending global [0 x %0] zeroinitializer
+
More information about the llvm-commits
mailing list