diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -2104,6 +2104,7 @@ return /*Changed*/ false; bool Changed = false; + auto *DL = &F.getParent()->getDataLayout(); // Collect a map of {backing storage : dbg.declares} (currently "backing // storage" is limited to Allocas). We'll use this to find dbg.declares to // delete after running `trackAssignments`. @@ -2128,13 +2129,15 @@ // FIXME: Skip VLAs for now (let these variables use dbg.declares). if (!Alloca->isStaticAlloca()) continue; + // Similarly, skip scalable vectors (use dbg.declares instead). + if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable()) + continue; DbgDeclares[Alloca].insert(DDI); Vars[Alloca].insert(VarRecord(DDI)); } } } - auto DL = std::make_unique(F.getParent()); // FIXME: Locals can be backed by caller allocas (sret, byval). // Note: trackAssignments doesn't respect dbg.declare's IR positions (as it // doesn't "understand" dbg.declares). However, this doesn't appear to break diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/declare-to-assign/scalable-vector.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/declare-to-assign/scalable-vector.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/assignment-tracking/declare-to-assign/scalable-vector.ll @@ -0,0 +1,41 @@ +; RUN: opt -passes=declare-to-assign %s -S | FileCheck %s + +;; Check declare-to-assign skips scalable vectors for now. i.e. do not replace +;; the dbg.declare with a dbg.assign intrinsic. + +; CHECK: call void @llvm.dbg.declare(metadata ptr %c + +define dso_local void @b() !dbg !9 { +entry: + %c = alloca , align 4 + call void @llvm.dbg.declare(metadata ptr %c, metadata !13, metadata !DIExpression()), !dbg !21 + ret void +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !5, !7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "test.c", directory: "/") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"target-abi", !"lp64"} +!7 = !{i32 8, !"SmallDataLimit", i32 8} +!8 = !{!"clang version 17.0.0"} +!9 = distinct !DISubprogram(name: "b", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12) +!10 = !DISubroutineType(types: !11) +!11 = !{null} +!12 = !{} +!13 = !DILocalVariable(name: "c", scope: !9, file: !1, line: 2, type: !14) +!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "a", file: !1, line: 1, baseType: !15) +!15 = !DIDerivedType(tag: DW_TAG_typedef, name: "__rvv_uint32m4_t", file: !16, baseType: !17) +!16 = !DIFile(filename: "test.c", directory: "/") +!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, flags: DIFlagVector, elements: !19) +!18 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) +!19 = !{!20} +!20 = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_constu, 4, DW_OP_div, DW_OP_constu, 4, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus)) +!21 = !DILocation(line: 2, column: 14, scope: !9) +