From 8ba2a590334e7b0609a15b9189b717e90f0b7241 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 11 Jun 2026 16:46:20 +0000 Subject: [PATCH] fir crashing with scalable TypeSizes From 537f3d3a7588d226b86590f97c4401107585e1ce Mon Sep 17 00:00:00 2001 From: Jakob Koschel Date: Thu, 5 Mar 2026 01:11:44 +0100 Subject: [PATCH] [SafeStack] Fix crashing with scalable TypeSizes (#180547) On e.g. aarch64 the TypeSize of scalar types can have a size that is not known at compile time. Currently when safestack occurs those it simply crashes as described in https://github.com/llvm/llvm-project/issues/175868. --- gnu/llvm/llvm/lib/CodeGen/SafeStack.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gnu/llvm/llvm/lib/CodeGen/SafeStack.cpp b/gnu/llvm/llvm/lib/CodeGen/SafeStack.cpp index 1c109a1f9fe..33ffd94e4f8 100644 --- a/gnu/llvm/llvm/lib/CodeGen/SafeStack.cpp +++ b/gnu/llvm/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);