[llvm-branch-commits] [llvm] release/22.x: [SafeStack] Fix crashing with scalable TypeSizes (#180547) (PR #203306)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jun 11 08:27:41 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: llvmbot
<details>
<summary>Changes</summary>
Backport 537f3d3a7588d226b86590f97c4401107585e1ce
Requested by: @<!-- -->brad0
---
Full diff: https://github.com/llvm/llvm-project/pull/203306.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SafeStack.cpp (+12)
- (added) llvm/test/CodeGen/AArch64/safestack_scalar.ll (+17)
``````````diff
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 1c109a1f9fed1..33ffd94e4f8f0 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -176,6 +176,8 @@ class SafeStack {
bool IsMemIntrinsicSafe(const MemIntrinsic *MI, const Use &U,
const Value *AllocaPtr, uint64_t AllocaSize);
+ bool IsAccessSafe(Value *Addr, TypeSize Size, const Value *AllocaPtr,
+ uint64_t AllocaSize);
bool IsAccessSafe(Value *Addr, uint64_t Size, const Value *AllocaPtr,
uint64_t AllocaSize);
@@ -206,6 +208,16 @@ uint64_t SafeStack::getStaticAllocaAllocationSize(const AllocaInst* AI) {
return Size;
}
+bool SafeStack::IsAccessSafe(Value *Addr, TypeSize AccessSize,
+ const Value *AllocaPtr, uint64_t AllocaSize) {
+ if (AccessSize.isScalable()) {
+ // In case we don't know the size at compile time we cannot verify if the
+ // access is safe.
+ return false;
+ }
+ return IsAccessSafe(Addr, AccessSize.getFixedValue(), AllocaPtr, AllocaSize);
+}
+
bool SafeStack::IsAccessSafe(Value *Addr, uint64_t AccessSize,
const Value *AllocaPtr, uint64_t AllocaSize) {
const SCEV *AddrExpr = SE.getSCEV(Addr);
diff --git a/llvm/test/CodeGen/AArch64/safestack_scalar.ll b/llvm/test/CodeGen/AArch64/safestack_scalar.ll
new file mode 100644
index 0000000000000..f8675e7a709d3
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/safestack_scalar.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -stop-after=safe-stack < %s | FileCheck %s
+
+define void @test_sve() safestack {
+entry:
+ %v = alloca <vscale x 16 x i8>, align 16
+ %val = load <vscale x 16 x i8>, ptr %v
+ ret void
+}
+
+; CHECK-LABEL: define void @test_sve(
+; CHECK: [[USP:%.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
+; CHECK: [[USST:%.*]] = getelementptr i8, ptr [[USP]], i32 -16
+; CHECK: store ptr [[USST]], ptr @__safestack_unsafe_stack_ptr
+; CHECK: [[PTR:%.*]] = getelementptr i8, ptr [[USP]], i32 -16
+; CHECK: load <vscale x 16 x i8>, ptr [[PTR]]
+; CHECK: store ptr [[USP]], ptr @__safestack_unsafe_stack_ptr
+; CHECK: ret void
``````````
</details>
https://github.com/llvm/llvm-project/pull/203306
More information about the llvm-branch-commits
mailing list