Skip to content

Commit ba099c5

Browse files
authored
[StackLifetime] Remove handling for lifetime size mismatch (#151965)
Split out from #150248: Since #150944 the size passed to lifetime.start/end is considered meaningless. The lifetime always applies to the whole alloca. Accordingly remove handling for size mismatch in the StackLifetime analysis.
1 parent fb632ed commit ba099c5

File tree

4 files changed

+6
-70
lines changed

4 files changed

+6
-70
lines changed

llvm/include/llvm/Analysis/StackLifetime.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ class StackLifetime {
121121
DenseMap<const BasicBlock *, SmallVector<std::pair<unsigned, Marker>, 4>>
122122
BBMarkers;
123123

124-
bool HasUnknownLifetimeStartOrEnd = false;
125-
126124
void dumpAllocas() const;
127125
void dumpBlockLiveness() const;
128126
void dumpLiveRanges() const;

llvm/lib/Analysis/StackLifetime.cpp

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -59,47 +59,20 @@ bool StackLifetime::isAliveAfter(const AllocaInst *AI,
5959
return getLiveRange(AI).test(InstNum);
6060
}
6161

62-
// Returns unique alloca annotated by lifetime marker only if
63-
// markers has the same size and points to the alloca start.
64-
static const AllocaInst *findMatchingAlloca(const IntrinsicInst &II,
65-
const DataLayout &DL) {
66-
const AllocaInst *AI = dyn_cast<AllocaInst>(II.getArgOperand(1));
67-
if (!AI)
68-
return nullptr;
69-
70-
auto AllocaSize = AI->getAllocationSize(DL);
71-
if (!AllocaSize)
72-
return nullptr;
73-
74-
auto *Size = dyn_cast<ConstantInt>(II.getArgOperand(0));
75-
if (!Size)
76-
return nullptr;
77-
int64_t LifetimeSize = Size->getSExtValue();
78-
79-
if (LifetimeSize != -1 && uint64_t(LifetimeSize) != *AllocaSize)
80-
return nullptr;
81-
82-
return AI;
83-
}
84-
8562
void StackLifetime::collectMarkers() {
8663
InterestingAllocas.resize(NumAllocas);
8764
DenseMap<const BasicBlock *, SmallDenseMap<const IntrinsicInst *, Marker>>
8865
BBMarkerSet;
8966

90-
const DataLayout &DL = F.getDataLayout();
91-
9267
// Compute the set of start/end markers per basic block.
9368
for (const BasicBlock *BB : depth_first(&F)) {
9469
for (const Instruction &I : *BB) {
9570
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
9671
if (!II || !II->isLifetimeStartOrEnd())
9772
continue;
98-
const AllocaInst *AI = findMatchingAlloca(*II, DL);
99-
if (!AI) {
100-
HasUnknownLifetimeStartOrEnd = true;
73+
const AllocaInst *AI = dyn_cast<AllocaInst>(II->getArgOperand(1));
74+
if (!AI)
10175
continue;
102-
}
10376
auto It = AllocaNumbering.find(AI);
10477
if (It == AllocaNumbering.end())
10578
continue;
@@ -328,20 +301,6 @@ StackLifetime::StackLifetime(const Function &F,
328301
}
329302

330303
void StackLifetime::run() {
331-
if (HasUnknownLifetimeStartOrEnd) {
332-
// There is marker which we can't assign to a specific alloca, so we
333-
// fallback to the most conservative results for the type.
334-
switch (Type) {
335-
case LivenessType::May:
336-
LiveRanges.resize(NumAllocas, getFullLiveRange());
337-
break;
338-
case LivenessType::Must:
339-
LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
340-
break;
341-
}
342-
return;
343-
}
344-
345304
LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
346305
for (unsigned I = 0; I < NumAllocas; ++I)
347306
if (!InterestingAllocas.test(I))

llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -786,27 +786,6 @@ end:
786786
ret void
787787
}
788788

789-
define void @alloca_size() {
790-
; CHECK-LABEL: define void @alloca_size
791-
entry:
792-
; CHECK: entry:
793-
; MAY-NEXT: Alive: <x>
794-
; MUST-NEXT: Alive: <>
795-
%x = alloca [5 x i32], align 4
796-
797-
call void @llvm.lifetime.start.p0(i64 15, ptr %x)
798-
; CHECK: call void @llvm.lifetime.start.p0(i64 15, ptr %x)
799-
; MAY-NEXT: Alive: <x>
800-
; MUST-NEXT: Alive: <>
801-
802-
call void @llvm.lifetime.end.p0(i64 15, ptr %x)
803-
; CHECK: call void @llvm.lifetime.end.p0(i64 15, ptr %x)
804-
; MAY-NEXT: Alive: <x>
805-
; MUST-NEXT: Alive: <>
806-
807-
ret void
808-
}
809-
810789
define void @multiple_start_end() {
811790
; CHECK-LABEL: define void @multiple_start_end
812791
entry:

llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ entry:
1818
%retval = alloca i32, align 4
1919
%c = alloca [2 x i8], align 1
2020

21-
; Memory is poisoned in prologue: F1F1F1F104F3F8F2
22-
; CHECK-UAS: store i64 -866676825215864335, ptr %{{[0-9]+}}
21+
; Memory is poisoned in prologue: F1F1F1F1F8F3F3F3
22+
; CHECK-UAS: store i64 -868082052615769615, ptr %{{[0-9]+}}
2323
; CHECK-UAS-SS-NOT: store i64
2424

25-
call void @llvm.lifetime.start.p0(i64 1, ptr %c)
25+
call void @llvm.lifetime.start.p0(i64 2, ptr %c)
2626
; Memory is unpoisoned at llvm.lifetime.start: 01
2727
; CHECK-UAS: store i8 2, ptr %{{[0-9]+}}
2828

2929
%ci = getelementptr inbounds [2 x i8], ptr %c, i64 0, i64 %i
3030
store volatile i32 0, ptr %retval
3131
store volatile i8 0, ptr %ci, align 1
3232

33-
call void @llvm.lifetime.end.p0(i64 1, ptr %c)
33+
call void @llvm.lifetime.end.p0(i64 2, ptr %c)
3434
; Memory is poisoned at llvm.lifetime.end: F8
3535
; CHECK-UAS: store i8 -8, ptr %{{[0-9]+}}
3636
; CHECK-UAS-SS-NOT: store i8 -8,

0 commit comments

Comments
 (0)