[llvm] [DebugInfo] Fix crash in declare-to-assign when memcpy writes to scalable-vector alloca (PR #194107)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 07:22:26 PDT 2026


================
@@ -0,0 +1,93 @@
+; RUN: opt -passes=declare-to-assign %s -S | FileCheck %s
+
+;; Check that declare-to-assign does not crash when a fixed-size memcpy writes
+;; into a scalable-vector alloca. getAssignmentInfoImpl must bail out when the
+;; destination alloca's type is scalable, not only when the store size itself is
+;; scalable. The dbg.declare for the scalable alloca should be preserved as-is.
+;;
+;; Derived from: https://github.com/llvm/llvm-project/issues/192728
+;;   #include <string.h>
+;;   #include <riscv_vector.h>
+;;   vint32m1_t get_i32x4(int* v) {
+;;     vint32m1_t r;
+;;     memcpy(&r, v, 16);
+;;     return r;
+;;   }
+;; Compiled with: clang -target riscv64-unknown-linux-gnu -march=rv64gcv -O1 -g
+
+;; The scalable-vector alloca must not receive a DIAssignID (i.e. declare-to-assign
+;; must leave it alone), and its dbg.declare must be preserved as-is.
+; CHECK-LABEL: @get_i32x4(
+; CHECK:         = alloca <vscale x 2 x i32>, align 4
+; CHECK-SAME:    {{$}}
+; CHECK:         #dbg_declare(ptr %3,
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+target triple = "riscv64-unknown-linux-gnu"
+
+define dso_local <vscale x 2 x i32> @get_i32x4(ptr noundef %0) #0 !dbg !16 {
+  %2 = alloca ptr, align 8
+  %3 = alloca <vscale x 2 x i32>, align 4
+  store ptr %0, ptr %2, align 8, !tbaa !31
+    #dbg_declare(ptr %2, !29, !DIExpression(), !34)
+  call void @llvm.lifetime.start.p0(ptr %3) #3, !dbg !35
+    #dbg_declare(ptr %3, !30, !DIExpression(), !36)
+  %4 = load ptr, ptr %2, align 8, !dbg !37, !tbaa !31
+  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 16, i1 false), !dbg !38
+  %5 = load <vscale x 2 x i32>, ptr %3, align 4, !dbg !39, !tbaa !40
+  call void @llvm.lifetime.end.p0(ptr %3) #3, !dbg !42
+  ret <vscale x 2 x i32> %5, !dbg !43
+}
+
+declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
+declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
+declare void @llvm.lifetime.end.p0(ptr captures(none)) #1
+
+attributes #0 = { nounwind uwtable vscale_range(2,1024) "target-cpu"="generic-rv64" "target-features"="+64bit,+v" }
+attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
+attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
+attributes #3 = { nounwind }
----------------
OCHyams wrote:

minor nit: If the attributes are not needed for the test we could remove them

https://github.com/llvm/llvm-project/pull/194107


More information about the llvm-commits mailing list