[llvm] r186778 - Don't crash when llvm.compiler.used becomes empty.
Rafael Espindola
rafael.espindola at gmail.com
Sat Jul 20 16:33:15 PDT 2013
Author: rafael
Date: Sat Jul 20 18:33:15 2013
New Revision: 186778
URL: http://llvm.org/viewvc/llvm-project?rev=186778&view=rev
Log:
Don't crash when llvm.compiler.used becomes empty.
GlobalOpt simplifies llvm.compiler.used by removing any members that are also
in the more strict llvm.used. Handle the special case where llvm.compiler.used
becomes empty.
Added:
llvm/trunk/test/Transforms/GlobalOpt/compiler-used.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=186778&r1=186777&r2=186778&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sat Jul 20 18:33:15 2013
@@ -3070,6 +3070,11 @@ static int compareNames(const void *A, c
static void setUsedInitializer(GlobalVariable &V,
SmallPtrSet<GlobalValue *, 8> Init) {
+ if (Init.empty()) {
+ V.eraseFromParent();
+ return;
+ }
+
SmallVector<llvm::Constant *, 8> UsedArray;
PointerType *Int8PtrTy = Type::getInt8PtrTy(V.getContext());
Added: llvm/trunk/test/Transforms/GlobalOpt/compiler-used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/compiler-used.ll?rev=186778&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/compiler-used.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/compiler-used.ll Sat Jul 20 18:33:15 2013
@@ -0,0 +1,16 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+; Test that when all members of llvm.compiler.used are found to be redundant
+; we delete it instead of crashing.
+
+define void @foo() {
+ ret void
+}
+
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+
+ at llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+
+; CHECK-NOT: @llvm.compiler.used
+; CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+; CHECK-NOT: @llvm.compiler.used
More information about the llvm-commits
mailing list