Skip to content

Commit 34ab569

Browse files
committed
Support zero size types in StackSafetyAnalysis.
Reviewers: vitalybuka Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73395
1 parent c3b80ad commit 34ab569

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Analysis/StackSafetyAnalysis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ StackSafetyLocalAnalysis::offsetFromAlloca(Value *Addr,
252252
ConstantRange
253253
StackSafetyLocalAnalysis::getAccessRange(Value *Addr, const Value *AllocaPtr,
254254
ConstantRange SizeRange) {
255+
// Zero-size loads and stores do not access memory.
256+
if (SizeRange.isEmptySet())
257+
return ConstantRange::getEmpty(PointerSize);
258+
255259
if (!SE.isSCEVable(Addr->getType()))
256260
return UnknownRange;
257261

llvm/test/Analysis/StackSafetyAnalysis/local.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,20 @@ entry:
368368
store <vscale x 4 x i32> %v, <vscale x 4 x i32>* %p, align 4
369369
ret void
370370
}
371+
372+
%zerosize_type = type {}
373+
374+
define void @ZeroSize(%zerosize_type *%p) {
375+
; CHECK-LABEL: @ZeroSize dso_preemptable{{$}}
376+
; CHECK-NEXT: args uses:
377+
; CHECK-NEXT: p[]: empty-set
378+
; CHECK-NEXT: allocas uses:
379+
; CHECK-NEXT: x[0]: empty-set
380+
; CHECK-NOT: ]:
381+
entry:
382+
%x = alloca %zerosize_type, align 4
383+
store %zerosize_type undef, %zerosize_type* %x, align 4
384+
store %zerosize_type undef, %zerosize_type* undef, align 4
385+
%val = load %zerosize_type, %zerosize_type* %p, align 4
386+
ret void
387+
}

0 commit comments

Comments
 (0)