1 // RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-print-local-scope | FileCheck %s
2 // RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
3 // RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | mlir-opt -allow-unregistered-dialect -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
4 // This test verifies that debug locations are round-trippable.
6 #set0 = affine_set<(d0) : (1 == 0)>
8 // CHECK-LABEL: func @inline_notation
9 func.func @inline_notation() -> i32 {
10 // CHECK: -> i32 loc("foo")
11 %1 = "foo"() : () -> i32 loc("foo")
13 // CHECK: arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
14 %2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
16 // CHECK: affine.for %arg0 loc("IVlocation") = 0 to 8 {
17 // CHECK: } loc(fused["foo", "mysource.cc":10:8])
18 affine.for %i0 loc("IVlocation") = 0 to 8 {
19 } loc(fused["foo", "mysource.cc":10:8])
21 // CHECK: } loc(fused<"myPass">["foo", "foo2"])
23 } loc(fused<"myPass">["foo", "foo2"])
25 // CHECK: } loc(fused<"myPass">["foo"])
27 } loc(fused<"myPass">["foo"])
29 // CHECK: return %0 : i32 loc(unknown)
30 return %1 : i32 loc(unknown)
33 // CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
34 func.func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
36 // CHECK-LABEL: func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10:0)})
37 func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10)})
38 // CHECK-LABEL: func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
39 func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
40 // CHECK-LABEL: func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
41 func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
42 // CHECK-LABEL: func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
43 func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
45 // Check that locations get properly escaped.
46 // CHECK-LABEL: func @escape_strings()
47 func.func @escape_strings() {
48 // CHECK: loc("escaped\0A")
49 "foo"() : () -> () loc("escaped\n")
51 // CHECK: loc("escaped\0A")
52 "foo"() : () -> () loc("escaped\0A")
54 // CHECK: loc("escaped\0A":0:0)
55 "foo"() : () -> () loc("escaped\n":0:0)
59 // CHECK-ALIAS: "foo.op"() : () -> () loc(#[[LOC:.*]])
60 "foo.op"() : () -> () loc(#loc)
62 // CHECK-LABEL: func @argLocs(
63 // CHECK-SAME: %arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:20),
64 func.func @argLocs(%x: i32,
65 // CHECK-SAME: %arg1: i64 loc("hotdog")
66 %y: i64 loc("hotdog")) {
70 // CHECK-LABEL: "foo.unknown_op_with_bbargs"()
71 // CHECK-ALIAS: "foo.unknown_op_with_bbargs"()
72 "foo.unknown_op_with_bbargs"() ({
73 // CHECK-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+2]]:7),
74 // CHECK-ALIAS-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:7),
76 // CHECK-SAME: %arg1: i32 loc("cheetos"),
77 // CHECK-ALIAS-SAME: %arg1: i32 loc("cheetos"),
78 %y: i32 loc("cheetos"),
79 // CHECK-SAME: %arg2: i32 loc("out_of_line_location2")):
80 // CHECK-ALIAS-SAME: %arg2: i32 loc("out_of_line_location2")):
81 %z: i32 loc("out_of_line_location2")):
82 %1 = arith.addi %x, %y : i32
83 "foo.yield"(%1) : (i32) -> ()
86 // CHECK-LABEL: func @location_name_child_is_name
87 func.func @location_name_child_is_name() {
88 // CHECK: "foo"("foo")
89 return loc("foo"("foo"))
92 // CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location")
93 #loc = loc("out_of_line_location")
95 // CHECK-LABEL: @optional_location_specifier
96 // CHECK: test.attr_with_loc("foo" loc("foo_loc"))
97 func.func @optional_location_specifier() {
98 test.attr_with_loc("foo" loc("foo_loc"))
102 // CHECK-LABEL: @dialect_location
103 // CHECK: test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir" * 32>))
104 func.func @dialect_location() {
105 test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir"*32>))