[llvm] r179460 - GlobalDCE: Fix an oversight in my last commit that could lead to crashes.
Benjamin Kramer
benny.kra at googlemail.com
Sat Apr 13 09:11:15 PDT 2013
Author: d0k
Date: Sat Apr 13 11:11:14 2013
New Revision: 179460
URL: http://llvm.org/viewvc/llvm-project?rev=179460&view=rev
Log:
GlobalDCE: Fix an oversight in my last commit that could lead to crashes.
There is a Constant with non-constant operands: blockaddress.
Added:
llvm/trunk/test/Transforms/GlobalDCE/indirectbr.ll
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=179460&r1=179459&r2=179460&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Sat Apr 13 11:11:14 2013
@@ -197,8 +197,8 @@ void GlobalDCE::MarkUsedGlobalsAsNeeded(
// use to the list of needed globals.
for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I) {
// If we've already processed this constant there's no need to do it again.
- Constant *Op = cast<Constant>(*I);
- if (SeenConstants.insert(Op))
+ Constant *Op = dyn_cast<Constant>(*I);
+ if (Op && SeenConstants.insert(Op))
MarkUsedGlobalsAsNeeded(Op);
}
}
Added: llvm/trunk/test/Transforms/GlobalDCE/indirectbr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/indirectbr.ll?rev=179460&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalDCE/indirectbr.ll (added)
+++ llvm/trunk/test/Transforms/GlobalDCE/indirectbr.ll Sat Apr 13 11:11:14 2013
@@ -0,0 +1,18 @@
+; RUN: opt -S -globaldce < %s | FileCheck %s
+
+ at L = internal unnamed_addr constant [3 x i8*] [i8* blockaddress(@test1, %L1), i8* blockaddress(@test1, %L2), i8* null], align 16
+
+; CHECK: @L = internal unnamed_addr constant
+
+define void @test1(i32 %idx) {
+entry:
+ br label %L1
+
+L1:
+ %arrayidx = getelementptr inbounds [3 x i8*]* @L, i32 0, i32 %idx
+ %l = load i8** %arrayidx
+ indirectbr i8* %l, [label %L1, label %L2]
+
+L2:
+ ret void
+}
More information about the llvm-commits
mailing list