Skip to content

Commit f6de530

Browse files
ChuanqiXu9vitalybuka
authored andcommitted
[NFC][StackSafety] Test that StackLifetime looks through stripPointerCasts
StackLifetime class collects lifetime marker of an `alloca` by collect the user of `BitCast` who is the user of the `alloca`. However, either the `alloca` itself could be used with the lifetime marker or the `BitCast` of the `alloca` could be transformed to other instructions. (e.g., it may be transformed to all zero reps in `InstCombine` pass). This patch tries to fix this process in `collectMarkers` functions. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D85399
1 parent 250f43d commit f6de530

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,50 @@ l2: ; preds = %l2, %entry
699699
br label %l2
700700
}
701701

702+
%struct.char_array = type { [500 x i8] }
703+
704+
define dso_local void @gep_test(i32 %cond) {
705+
; CHECK-LABEL: define dso_local void @gep_test
706+
entry:
707+
; CHECK: entry:
708+
; CHECK-NEXT: Alive: <>
709+
%a = alloca %struct.char_array, align 8
710+
%b = alloca %struct.char_array, align 8
711+
%tobool.not = icmp eq i32 %cond, 0
712+
br i1 %tobool.not, label %if.else, label %if.then
713+
714+
if.then: ; preds = %entry
715+
; CHECK: if.then:
716+
; CHECK-NEXT: Alive: <>
717+
%0 = getelementptr inbounds %struct.char_array, %struct.char_array* %a, i64 0, i32 0, i64 0
718+
call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
719+
; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
720+
; CHECK-NEXT: Alive: <a>
721+
tail call void @capture8(i8* %0)
722+
call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
723+
; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
724+
; CHECK-NEXT: Alive: <>
725+
br label %if.end
726+
727+
if.else: ; preds = %entry
728+
; CHECK: if.else:
729+
; CHECK-NEXT: Alive: <>
730+
%1 = getelementptr inbounds %struct.char_array, %struct.char_array* %b, i64 0, i32 0, i64 0
731+
call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
732+
; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
733+
; CHECK-NEXT: Alive: <b>
734+
tail call void @capture8(i8* %1)
735+
call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
736+
; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
737+
; CHECK-NEXT: Alive: <>
738+
br label %if.end
739+
740+
if.end: ; preds = %if.else, %if.then
741+
; CHECK: if.end:
742+
; CHECK-NEXT: Alive: <>
743+
ret void
744+
}
745+
702746
define void @if_must(i1 %a) {
703747
; CHECK-LABEL: define void @if_must
704748
entry:

0 commit comments

Comments
 (0)