[llvm] [SPIRV] Addition of extension SPV_KHR_non_semantic_info (PR #165302)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 02:35:55 PDT 2025


Keenuts wrote:

Seems like having a method yields a crash on this PR:
(Compiled in 2 steps, HLSL -> IR, IR -> SPIR-V + debug)

```hlsl
// RUN: %clang --driver-mode=dxc %s -T cs_6_8 -E main -O3 -spirv -g

class A {
  int foo(int value) {
    return value * 2;
  }
};

RWStructuredBuffer<uint> buffer;

[numthreads(1, 1, 1)]
void main() {
  A a;
  buffer[0] = a.foo(buffer[0]);
}
```


```llvm
; RUN: %llc --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown /tmp/a.ll -o -

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G10"
target triple = "spirv1.6-unknown-vulkan1.3-compute"

@.str = private unnamed_addr constant [7 x i8] c"buffer\00", align 1

; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none)
define void @main() local_unnamed_addr #0 {
entry:
    #dbg_value(i32 0, !69, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
    #dbg_value(i32 0, !72, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
    #dbg_value(i32 1, !73, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
    #dbg_value(i32 0, !74, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
    #dbg_value(ptr @.str, !75, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
    #dbg_value(i32 1, !76, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !78)
  %0 = tail call target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromimplicitbinding.tspirv.VulkanBuffer_a0i32_12_1t(i32 0, i32 0, i32 1, i32 0, ptr nonnull @.str), !dbg !78
    #dbg_value(ptr poison, !87, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !91)
    #dbg_value(ptr undef, !90, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !91)
    #dbg_value(ptr poison, !93, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !97)
    #dbg_value(i32 0, !96, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !97)
  %1 = tail call noundef align 4 dereferenceable(4) ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.VulkanBuffer_a0i32_12_1t(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %0, i32 0), !dbg !97
  %2 = load i32, ptr addrspace(11) %1, align 4, !dbg !109, !tbaa !65
    #dbg_value(ptr undef, !110, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !115)
    #dbg_value(i32 %2, !113, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !115)
  %mul.i = shl nsw i32 %2, 1, !dbg !117
    #dbg_value(ptr poison, !93, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !118)
    #dbg_value(i32 0, !96, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !118)
  store i32 %mul.i, ptr addrspace(11) %1, align 4, !dbg !120, !tbaa !65
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
declare target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromimplicitbinding.tspirv.VulkanBuffer_a0i32_12_1t(i32, i32, i32, i32, ptr) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
declare ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.VulkanBuffer_a0i32_12_1t(target("spirv.VulkanBuffer", [0 x i32], 12, 1), i32) #1

attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(none) }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!60, !61, !62, !63}
!llvm.ident = !{!64}
!llvm.errno.tbaa = !{!65}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_11, file: !1, producer: "clang version 22.0.0git (/home/user/projects/llvm-project/clang 07b96bbf70c7773e44e31e51b4f1aac63b815a1f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !57, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "/home/user/projects/llvm-project/repro.hlsl", directory: "/home/user/projects/llvm-project")
!2 = !{!3}
!3 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "RWStructuredBuffer<unsigned int>", scope: !4, size: 128, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !5, templateParams: !55, identifier: "_ZTSN4hlsl18RWStructuredBufferIjEE")
!4 = !DINamespace(name: "hlsl", scope: null)
!5 = !{!6, !10, !11, !15, !20, !24, !32, !33, !39, !43, !46, !49, !50}
!6 = !DIDerivedType(tag: DW_TAG_member, name: "__handle", scope: !3, file: !7, line: 15, baseType: !8, size: 64)
!7 = !DIFile(filename: "repro.hlsl", directory: "/home/user/projects/llvm-project")
!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
!9 = !DICompositeType(tag: DW_TAG_structure_type, name: "__hlsl_resource_t", file: !1, flags: DIFlagFwdDecl)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "__counter_handle", scope: !3, file: !7, line: 15, baseType: !8, size: 64, offset: 64)
!11 = !DISubprogram(name: "RWStructuredBuffer", linkageName: "_ZN4hlsl18RWStructuredBufferIjEC4Ev", scope: !3, file: !7, type: !12, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!12 = !DISubroutineType(types: !13)
!13 = !{null, !14}
!14 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !3, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer, dwarfAddressSpace: 0)
!15 = !DISubprogram(name: "RWStructuredBuffer", linkageName: "_ZN4hlsl18RWStructuredBufferIjEC4ERKS1_", scope: !3, file: !7, type: !16, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!16 = !DISubroutineType(types: !17)
!17 = !{null, !14, !18}
!18 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !19, size: 64, dwarfAddressSpace: 0)
!19 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !3)
!20 = !DISubprogram(name: "operator=", linkageName: "_ZN4hlsl18RWStructuredBufferIjEaSERKS1_", scope: !3, file: !7, type: !21, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!21 = !DISubroutineType(types: !22)
!22 = !{!23, !14, !18}
!23 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !3, size: 64, dwarfAddressSpace: 0)
!24 = !DISubprogram(name: "__createFromBindingWithImplicitCounter", linkageName: "_ZN4hlsl18RWStructuredBufferIjE38__createFromBindingWithImplicitCounterEjjijPKcj", scope: !3, file: !7, type: !25, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagOptimized)
!25 = !DISubroutineType(types: !26)
!26 = !{!3, !27, !27, !28, !27, !29, !27}
!27 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
!28 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !30, size: 64, dwarfAddressSpace: 0)
!30 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !31)
!31 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!32 = !DISubprogram(name: "__createFromImplicitBindingWithImplicitCounter", linkageName: "_ZN4hlsl18RWStructuredBufferIjE46__createFromImplicitBindingWithImplicitCounterEjjijPKcj", scope: !3, file: !7, type: !25, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagOptimized)
!33 = !DISubprogram(name: "operator[]", linkageName: "_ZNK4hlsl18RWStructuredBufferIjEixEj", scope: !3, file: !7, type: !34, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!34 = !DISubroutineType(types: !35)
!35 = !{!36, !38, !27}
!36 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !37, size: 64, dwarfAddressSpace: 11)
!37 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !27)
!38 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !19, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer, dwarfAddressSpace: 0)
!39 = !DISubprogram(name: "operator[]", linkageName: "_ZN4hlsl18RWStructuredBufferIjEixEj", scope: !3, file: !7, type: !40, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!40 = !DISubroutineType(types: !41)
!41 = !{!42, !14, !27}
!42 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !27, size: 64, dwarfAddressSpace: 11)
!43 = !DISubprogram(name: "Load", linkageName: "_ZN4hlsl18RWStructuredBufferIjE4LoadEj", scope: !3, file: !7, type: !44, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!44 = !DISubroutineType(types: !45)
!45 = !{!27, !14, !27}
!46 = !DISubprogram(name: "IncrementCounter", linkageName: "_ZN4hlsl18RWStructuredBufferIjE16IncrementCounterEv", scope: !3, file: !7, type: !47, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!47 = !DISubroutineType(types: !48)
!48 = !{!27, !14}
!49 = !DISubprogram(name: "DecrementCounter", linkageName: "_ZN4hlsl18RWStructuredBufferIjE16DecrementCounterEv", scope: !3, file: !7, type: !47, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!50 = !DISubprogram(name: "GetDimensions", linkageName: "_ZN4hlsl18RWStructuredBufferIjE13GetDimensionsERjS2_", scope: !3, file: !7, type: !51, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!51 = !DISubroutineType(types: !52)
!52 = !{null, !14, !53, !53}
!53 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !54)
!54 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !27, size: 64, dwarfAddressSpace: 0)
!55 = !{!56}
!56 = !DITemplateTypeParameter(name: "element_type", type: !27)
!57 = !{!58}
!58 = !DIGlobalVariableExpression(var: !59, expr: !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef))
!59 = distinct !DIGlobalVariable(name: "buffer", linkageName: "_ZL6buffer", scope: !0, file: !7, line: 9, type: !3, isLocal: true, isDefinition: true)
!60 = !{i32 7, !"Dwarf Version", i32 4}
!61 = !{i32 2, !"Debug Info Version", i32 3}
!62 = !{i32 1, !"wchar_size", i32 4}
!63 = !{i32 7, !"frame-pointer", i32 2}
!64 = !{!"clang version 22.0.0git (/home/user/projects/llvm-project/clang 07b96bbf70c7773e44e31e51b4f1aac63b815a1f)"}
!65 = !{!66, !66, i64 0}
!66 = !{!"int", !67, i64 0}
!67 = !{!"omnipotent char", !68, i64 0}
!68 = !{!"Simple C++ TBAA"}
!69 = !DILocalVariable(name: "orderId", arg: 1, scope: !70, file: !7, type: !27)
!70 = distinct !DISubprogram(name: "__createFromImplicitBindingWithImplicitCounter", linkageName: "_ZN4hlsl18RWStructuredBufferIjE46__createFromImplicitBindingWithImplicitCounterEjjijPKcj", scope: !3, file: !7, line: 15, type: !25, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !32, retainedNodes: !71)
!71 = !{!69, !72, !73, !74, !75, !76, !77}
!72 = !DILocalVariable(name: "spaceNo", arg: 2, scope: !70, file: !7, type: !27)
!73 = !DILocalVariable(name: "range", arg: 3, scope: !70, file: !7, type: !28)
!74 = !DILocalVariable(name: "index", arg: 4, scope: !70, file: !7, type: !27)
!75 = !DILocalVariable(name: "name", arg: 5, scope: !70, file: !7, type: !29)
!76 = !DILocalVariable(name: "counterOrderId", arg: 6, scope: !70, file: !7, type: !27)
!77 = !DILocalVariable(name: "tmp", scope: !70, file: !7, type: !3)
!78 = !DILocation(line: 0, scope: !70, inlinedAt: !79)
!79 = distinct !DILocation(line: 0, scope: !80, inlinedAt: !83)
!80 = distinct !DISubprogram(name: "__cxx_global_var_init", scope: !7, file: !7, type: !81, flags: DIFlagArtificial | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!81 = !DISubroutineType(types: !82)
!82 = !{null}
!83 = distinct !DILocation(line: 0, scope: !84)
!84 = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_repro.hlsl", scope: !7, file: !7, type: !85, flags: DIFlagArtificial | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!85 = !DISubroutineType(types: !86)
!86 = !{}
!87 = !DILocalVariable(name: "this", arg: 1, scope: !88, type: !23, flags: DIFlagArtificial | DIFlagObjectPointer)
!88 = distinct !DISubprogram(name: "RWStructuredBuffer", linkageName: "_ZN4hlsl18RWStructuredBufferIjEC2ERKS1_", scope: !3, file: !7, line: 15, type: !16, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !15, retainedNodes: !89)
!89 = !{!87, !90}
!90 = !DILocalVariable(name: "other", arg: 2, scope: !88, file: !7, type: !18)
!91 = !DILocation(line: 0, scope: !88, inlinedAt: !92)
!92 = distinct !DILocation(line: 0, scope: !70, inlinedAt: !79)
!93 = !DILocalVariable(name: "this", arg: 1, scope: !94, type: !23, flags: DIFlagArtificial | DIFlagObjectPointer)
!94 = distinct !DISubprogram(name: "operator[]", linkageName: "_ZN4hlsl18RWStructuredBufferIjEixEj", scope: !3, file: !7, line: 6, type: !40, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !39, retainedNodes: !95)
!95 = !{!93, !96}
!96 = !DILocalVariable(name: "Index", arg: 2, scope: !94, file: !7, type: !27)
!97 = !DILocation(line: 0, scope: !94, inlinedAt: !98)
!98 = distinct !DILocation(line: 14, column: 21, scope: !99)
!99 = distinct !DISubprogram(name: "main", linkageName: "_Z4mainv", scope: !7, file: !7, line: 12, type: !100, scopeLine: 12, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !101)
!100 = !DISubroutineType(cc: DW_CC_LLVM_SpirFunction, types: !82)
!101 = !{!102}
!102 = !DILocalVariable(name: "a", scope: !99, file: !7, line: 13, type: !103)
!103 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !7, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !104, identifier: "_ZTS1A")
!104 = !{!105}
!105 = !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEi", scope: !103, file: !7, line: 4, type: !106, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
!106 = !DISubroutineType(cc: DW_CC_LLVM_SpirFunction, types: !107)
!107 = !{!28, !108, !28}
!108 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !103, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer, dwarfAddressSpace: 0)
!109 = !DILocation(line: 14, column: 21, scope: !99)
!110 = !DILocalVariable(name: "this", arg: 1, scope: !111, type: !114, flags: DIFlagArtificial | DIFlagObjectPointer)
!111 = distinct !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEi", scope: !103, file: !7, line: 4, type: !106, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !105, retainedNodes: !112)
!112 = !{!110, !113}
!113 = !DILocalVariable(name: "value", arg: 2, scope: !111, file: !7, line: 4, type: !28)
!114 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !103, size: 64, dwarfAddressSpace: 0)
!115 = !DILocation(line: 0, scope: !111, inlinedAt: !116)
!116 = distinct !DILocation(line: 14, column: 17, scope: !99)
!117 = !DILocation(line: 5, column: 18, scope: !111, inlinedAt: !116)
!118 = !DILocation(line: 0, scope: !94, inlinedAt: !119)
!119 = distinct !DILocation(line: 14, column: 3, scope: !99)
!120 = !DILocation(line: 14, column: 13, scope: !99)
```

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


More information about the llvm-commits mailing list