is an array of structures doesn't imply it's a ConstantArray of
ConstantStruct.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129207
91177308-0d34-0410-b5e6-
96231b3b80d8
// 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;
--- /dev/null
+; RUN: opt < %s -globalopt -disable-output
+
+%0 = type { i32, void ()* }
+@llvm.global_ctors = appending global [0 x %0] zeroinitializer
+