Skip to content

Commit ab7be41

Browse files
committed
[GlobalOpt] Don't replace aliasee with alias that has weak linkage
1 parent 937ab67 commit ab7be41

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,9 @@ static bool mayHaveOtherReferences(GlobalValue &GV, const LLVMUsed &U) {
22242224

22252225
static bool hasUsesToReplace(GlobalAlias &GA, const LLVMUsed &U,
22262226
bool &RenameTarget) {
2227+
if (GA.isWeakForLinker())
2228+
return false;
2229+
22272230
RenameTarget = false;
22282231
bool Ret = false;
22292232
if (hasUseOtherThanLLVMUsed(GA, U))

llvm/test/Transforms/GlobalOpt/alias-weak.ll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,27 @@ define void @baz() {
1919
ret void
2020
}
2121

22-
; FIXME: We cannot use `f1_alias` to replace `f1` because they are both in use
22+
; We cannot use `f1_alias` to replace `f1` because they are both in use
2323
; and `f1_alias` could be replaced at link time.
2424
define internal void @f1() {
2525
ret void
2626
}
2727

28+
; FIXME: We can use `f2_alias` to replace `f2` because `b2` is not in use.
2829
define internal void @f2() {
2930
ret void
3031
}
32+
;.
33+
; CHECK: @f1_alias = linkonce_odr hidden alias void (), ptr @f1
34+
; CHECK: @f2_alias = linkonce_odr hidden alias void (), ptr @f2
35+
;.
3136
; CHECK-LABEL: define void @foo() local_unnamed_addr {
3237
; CHECK-NEXT: call void @f1_alias()
3338
; CHECK-NEXT: ret void
3439
;
3540
;
3641
; CHECK-LABEL: define void @bar() local_unnamed_addr {
37-
; CHECK-NEXT: call void @f1_alias()
42+
; CHECK-NEXT: call void @f1()
3843
; CHECK-NEXT: ret void
3944
;
4045
;
@@ -43,10 +48,10 @@ define internal void @f2() {
4348
; CHECK-NEXT: ret void
4449
;
4550
;
46-
; CHECK-LABEL: define linkonce_odr hidden void @f1_alias() local_unnamed_addr {
51+
; CHECK-LABEL: define internal void @f1() {
4752
; CHECK-NEXT: ret void
4853
;
4954
;
50-
; CHECK-LABEL: define linkonce_odr hidden void @f2_alias() local_unnamed_addr {
55+
; CHECK-LABEL: define internal void @f2() {
5156
; CHECK-NEXT: ret void
5257
;

0 commit comments

Comments
 (0)