Skip to content

Commit 70b5a22

Browse files
authored
[hwasan] Don't crash on vscale allocas (#90932)
getAllocaSizeInBytes will crash casting size to constant.
1 parent e450f98 commit 70b5a22

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ void StackInfoBuilder::visit(Instruction &Inst) {
180180

181181
bool StackInfoBuilder::isInterestingAlloca(const AllocaInst &AI) {
182182
return (AI.getAllocatedType()->isSized() &&
183+
// FIXME: support vscale.
184+
!AI.getAllocatedType()->isScalableTy() &&
183185
// FIXME: instrument dynamic allocas, too
184186
AI.isStaticAlloca() &&
185187
// alloca() may be called with 0 size, ignore it.

llvm/test/Instrumentation/HWAddressSanitizer/alloca.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ entry:
110110
ret void, !dbg !24
111111
}
112112

113+
define void @test_vscale_alloca() sanitize_hwaddress {
114+
; DYNAMIC-SHADOW-LABEL: define void @test_vscale_alloca(
115+
; DYNAMIC-SHADOW-SAME: ) #[[ATTR0]] {
116+
; DYNAMIC-SHADOW-NEXT: [[X:%.*]] = alloca <vscale x 4 x i64>, align 32
117+
; DYNAMIC-SHADOW-NEXT: call void @use32(ptr nonnull [[X]])
118+
; DYNAMIC-SHADOW-NEXT: ret void
119+
;
120+
; ZERO-BASED-SHADOW-LABEL: define void @test_vscale_alloca(
121+
; ZERO-BASED-SHADOW-SAME: ) #[[ATTR0]] {
122+
; ZERO-BASED-SHADOW-NEXT: [[X:%.*]] = alloca <vscale x 4 x i64>, align 32
123+
; ZERO-BASED-SHADOW-NEXT: call void @use32(ptr nonnull [[X]])
124+
; ZERO-BASED-SHADOW-NEXT: ret void
125+
;
126+
%x = alloca <vscale x 4 x i64>
127+
call void @use32(ptr nonnull %x)
128+
ret void
129+
}
130+
113131
declare void @llvm.dbg.value(metadata, metadata, metadata)
114132

115133
!llvm.dbg.cu = !{!0}

0 commit comments

Comments
 (0)