[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / Target / LLVMIR / llvmir-debug.mlir
blob6e07b685abd9eb3698e262c2281484475bd60db7
1 // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
3 // CHECK-LABEL: define void @func_with_empty_named_info()
4 // Check that translation doens't crash in the presence of an inlineble call
5 // with a named loc that has no backing source info.
6 llvm.func @callee() {
7   llvm.return
8 } loc("calleesource.cc":1:1)
9 llvm.func @func_with_empty_named_info() {
10   llvm.call @callee() : () -> () loc("named with no line info")
11   llvm.return
14 // CHECK-LABEL: define void @func_no_debug()
15 // CHECK-NOT: !dbg
16 llvm.func @func_no_debug() {
17   llvm.return loc(unknown)
18 } loc(unknown)
20 #file = #llvm.di_file<"foo.mlir" in "/test/">
21 #si64 = #llvm.di_basic_type<
22   // Omit the optional sizeInBits and encoding parameters.
23   tag = DW_TAG_base_type, name = "si64"
25 #si32 = #llvm.di_basic_type<
26   tag = DW_TAG_base_type, name = "si32",
27   sizeInBits = 32, encoding = DW_ATE_signed
29 #ptr = #llvm.di_derived_type<
30   tag = DW_TAG_pointer_type, baseType = #si32,
31   sizeInBits = 64, alignInBits = 32, offsetInBits = 8
33 #named = #llvm.di_derived_type<
34   // Specify the name parameter.
35   tag = DW_TAG_pointer_type, name = "named", baseType = #si32
37 #cu = #llvm.di_compile_unit<
38   sourceLanguage = DW_LANG_C, file = #file, producer = "MLIR",
39   isOptimized = true, emissionKind = Full
41 #composite = #llvm.di_composite_type<
42   tag = DW_TAG_structure_type, name = "composite", file = #file,
43   line = 42, sizeInBits = 64, alignInBits = 32,
44   elements = #llvm.di_subrange<count = 4>
46 #vector = #llvm.di_composite_type<
47   tag = DW_TAG_array_type, name = "array", file = #file,
48   baseType = #si64, flags = Vector,
49   elements = #llvm.di_subrange<lowerBound = 0, upperBound = 4, stride = 1>
51 #null = #llvm.di_null_type
52 #spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #null, #si64, #ptr, #named, #composite, #vector>
53 #toplevel_namespace = #llvm.di_namespace<
54   name = "toplevel", exportSymbols = true
56 #nested_namespace = #llvm.di_namespace<
57   name = "nested", scope = #toplevel_namespace, exportSymbols = false
59 #sp0 = #llvm.di_subprogram<
60   compileUnit = #cu, scope = #nested_namespace, name = "func_with_debug", linkageName = "func_with_debug",
61   file = #file, line = 3, scopeLine = 3, subprogramFlags = "Definition|Optimized", type = #spType0
63 #calleeType = #llvm.di_subroutine_type<
64   // Omit the optional callingConvention parameter.
65   types = #si64, #si64>
66 #callee = #llvm.di_subprogram<
67   // Omit the optional linkageName, line, and scopeLine parameters.
68   compileUnit = #cu, scope = #composite, name = "callee",
69   file = #file, subprogramFlags = "Definition", type = #calleeType
71 #fileScope = #llvm.di_lexical_block_file<scope = #sp0, file = #file, discriminator = 0>
72 #blockScope = #llvm.di_lexical_block<scope = #sp0>
73 #variable = #llvm.di_local_variable<scope = #fileScope, name = "arg", file = #file, line = 6, arg = 1, alignInBits = 32, type = #si64>
74 #variableAddr = #llvm.di_local_variable<scope = #blockScope, name = "alloc">
76 #spType1 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
77 #sp1 = #llvm.di_subprogram<
78   compileUnit = #cu, scope = #file, name = "empty_types",
79   file = #file, subprogramFlags = "Definition", type = #spType1
82 // CHECK-LABEL: define void @func_with_debug(
83 // CHECK-SAME: i64 %[[ARG:.*]]) !dbg ![[FUNC_LOC:[0-9]+]]
84 llvm.func @func_with_debug(%arg: i64) {
85   // CHECK: %[[ALLOC:.*]] = alloca
86   %allocCount = llvm.mlir.constant(1 : i32) : i32
87   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr<i64>
89   // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression())
90   // CHECK: call void @llvm.dbg.addr(metadata ptr %[[ALLOC]], metadata ![[ADDR_LOC:[0-9]+]], metadata !DIExpression())
91   // CHECK: call void @llvm.dbg.declare(metadata ptr %[[ALLOC]], metadata ![[ADDR_LOC]], metadata !DIExpression())
92   llvm.intr.dbg.value #variable = %arg : i64
93   llvm.intr.dbg.addr #variableAddr = %alloc : !llvm.ptr<i64>
94   llvm.intr.dbg.declare #variableAddr = %alloc : !llvm.ptr<i64>
96   // CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
97   llvm.call @func_no_debug() : () -> () loc(callsite("mysource.cc":3:4 at "mysource.cc":5:6))
99   // CHECK: call void @func_no_debug(), !dbg ![[FILE_LOC:[0-9]+]]
100   llvm.call @func_no_debug() : () -> () loc("foo.mlir":1:2)
102   // CHECK: call void @func_no_debug(), !dbg ![[NAMED_LOC:[0-9]+]]
103   llvm.call @func_no_debug() : () -> () loc("named"("foo.mlir":10:10))
105   // CHECK: call void @func_no_debug(), !dbg ![[FUSED_LOC:[0-9]+]]
106   llvm.call @func_no_debug() : () -> () loc(fused[callsite("mysource.cc":5:6 at "mysource.cc":1:1), "mysource.cc":1:1])
108   // CHECK: add i64 %[[ARG]], %[[ARG]], !dbg ![[FUSEDWITH_LOC:[0-9]+]]
109   %sum = llvm.add %arg, %arg : i64 loc(fused<#callee>[callsite("foo.mlir":2:4 at fused<#sp0>["foo.mlir":28:5])])
111   llvm.return
112 } loc(fused<#sp0>["foo.mlir":1:1])
114 // CHECK: define void @empty_types() !dbg ![[EMPTY_TYPES_LOC:[0-9]+]]
115 llvm.func @empty_types() {
116   llvm.return
117 } loc(fused<#sp1>["foo.mlir":2:1])
119 // CHECK: ![[CU_LOC:.*]] = distinct !DICompileUnit(language: DW_LANG_C, file: ![[CU_FILE_LOC:.*]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
120 // CHECK: ![[CU_FILE_LOC]] = !DIFile(filename: "foo.mlir", directory: "/test/")
122 // CHECK: ![[FUNC_LOC]] = distinct !DISubprogram(name: "func_with_debug", linkageName: "func_with_debug", scope: ![[NESTED_NAMESPACE:.*]], file: ![[CU_FILE_LOC]], line: 3, type: ![[FUNC_TYPE:.*]], scopeLine: 3, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: ![[CU_LOC]])
123 // CHECK: ![[NESTED_NAMESPACE]] = !DINamespace(name: "nested", scope: ![[TOPLEVEL_NAMESPACE:.*]])
124 // CHECK: ![[TOPLEVEL_NAMESPACE]] = !DINamespace(name: "toplevel", scope: null, exportSymbols: true)
125 // CHECK: ![[FUNC_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[FUNC_ARGS:.*]])
126 // CHECK: ![[FUNC_ARGS]] = !{null, ![[ARG_TYPE:.*]], ![[PTR_TYPE:.*]], ![[NAMED_TYPE:.*]], ![[COMPOSITE_TYPE:.*]], ![[VECTOR_TYPE:.*]]}
127 // CHECK: ![[ARG_TYPE]] = !DIBasicType(name: "si64")
128 // CHECK: ![[PTR_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64, align: 32, offset: 8)
129 // CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "si32", size: 32, encoding: DW_ATE_signed)
130 // CHECK: ![[NAMED_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "named", baseType: ![[BASE_TYPE:.*]])
131 // CHECK: ![[COMPOSITE_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "composite", file: ![[CU_FILE_LOC]], line: 42, size: 64, align: 32, elements: ![[COMPOSITE_ELEMENTS:.*]])
132 // CHECK: ![[COMPOSITE_ELEMENTS]] = !{![[COMPOSITE_ELEMENT:.*]]}
133 // CHECK: ![[COMPOSITE_ELEMENT]] = !DISubrange(count: 4)
134 // CHECK: ![[VECTOR_TYPE]] = !DICompositeType(tag: DW_TAG_array_type, name: "array", file: ![[CU_FILE_LOC]], baseType: ![[ARG_TYPE]], flags: DIFlagVector, elements: ![[VECTOR_ELEMENTS:.*]])
135 // CHECK: ![[VECTOR_ELEMENTS]] = !{![[VECTOR_ELEMENT:.*]]}
136 // CHECK: ![[VECTOR_ELEMENT]] = !DISubrange(lowerBound: 0, upperBound: 4, stride: 1)
138 // CHECK: ![[VAR_LOC]] = !DILocalVariable(name: "arg", arg: 1, scope: ![[VAR_SCOPE:.*]], file: ![[CU_FILE_LOC]], line: 6, type: ![[ARG_TYPE]], align: 32)
139 // CHECK: ![[VAR_SCOPE]] = distinct !DILexicalBlockFile(scope: ![[FUNC_LOC]], file: ![[CU_FILE_LOC]], discriminator: 0)
140 // CHECK: ![[ADDR_LOC]] = !DILocalVariable(name: "alloc", scope: ![[BLOCK_LOC:.*]])
141 // CHECK: ![[BLOCK_LOC]] = distinct !DILexicalBlock(scope: ![[FUNC_LOC]])
143 // CHECK-DAG: ![[CALLSITE_LOC]] = !DILocation(line: 3, column: 4,
144 // CHECK-DAG: ![[FILE_LOC]] = !DILocation(line: 1, column: 2,
145 // CHECK-DAG: ![[NAMED_LOC]] = !DILocation(line: 10, column: 10
146 // CHECK-DAG: ![[FUSED_LOC]] = !DILocation(line: 1, column: 1
148 // CHECK: ![[FUSEDWITH_LOC]] = !DILocation(line: 2, column: 4, scope: ![[FUSEDWITH_SCOPE:.*]], inlinedAt: ![[INLINE_LOC:.*]])
149 // CHECK: ![[FUSEDWITH_SCOPE]] = !DILexicalBlockFile(scope: ![[CALLEE_LOC:.*]], file:
150 // CHECK: ![[CALLEE_LOC]] = distinct !DISubprogram(name: "callee", scope: ![[COMPOSITE_TYPE]], file: ![[CU_FILE_LOC]], type: ![[CALLEE_TYPE:.*]], spFlags: DISPFlagDefinition, unit: ![[CU_LOC]])
151 // CHECK: ![[CALLEE_TYPE]] = !DISubroutineType(types: ![[CALLEE_ARGS:.*]])
152 // CHECK: ![[CALLEE_ARGS]] = !{![[ARG_TYPE:.*]], ![[ARG_TYPE:.*]]}
153 // CHECK: ![[INLINE_LOC]] = !DILocation(line: 28, column: 5,
155 // CHECK: ![[EMPTY_TYPES_LOC]] = distinct !DISubprogram(name: "empty_types", scope: ![[CU_FILE_LOC]], file: ![[CU_FILE_LOC]], type: ![[EMPTY_TYPES_TYPE:.*]], spFlags: DISPFlagDefinition
156 // CHECK: ![[EMPTY_TYPES_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[EMPTY_TYPES_ARGS:.*]])
157 // CHECK: ![[EMPTY_TYPES_ARGS]] = !{}