1 # RUN: %PYTHON %s | FileCheck %s
8 print("\nTEST:", f
.__name
__)
11 assert Context
._get
_live
_count
() == 0
15 # CHECK-LABEL: TEST: test_exception
19 ctx
.allow_unregistered_dialects
= True
24 "test.use"(%0) : (i64) -> () loc("use")
25 %0 = "test.def"() : () -> i64 loc("def")
31 except MLIRError
as e
:
33 # CHECK: Unable to parse operation assembly:
34 # CHECK: error: "use": operand #0 does not dominate this use
35 # CHECK: note: "use": see current operation: "test.use"(%0) : (i64) -> ()
36 # CHECK: note: "def": operand defined here (op in the same block)
38 print(f
"Exception: <{e}>")
40 # CHECK: message: Unable to parse operation assembly
41 print(f
"message: {e.message}")
43 # CHECK: error_diagnostics[0]: loc("use") operand #0 does not dominate this use
44 # CHECK: error_diagnostics[0].notes[0]: loc("use") see current operation: "test.use"(%0) : (i64) -> ()
45 # CHECK: error_diagnostics[0].notes[1]: loc("def") operand defined here (op in the same block)
47 "error_diagnostics[0]: ",
48 e
.error_diagnostics
[0].location
,
49 e
.error_diagnostics
[0].message
,
52 "error_diagnostics[0].notes[0]: ",
53 e
.error_diagnostics
[0].notes
[0].location
,
54 e
.error_diagnostics
[0].notes
[0].message
,
57 "error_diagnostics[0].notes[1]: ",
58 e
.error_diagnostics
[0].notes
[1].location
,
59 e
.error_diagnostics
[0].notes
[1].message
,
63 # CHECK-LABEL: test_emit_error_diagnostics
65 def test_emit_error_diagnostics():
67 loc
= Location
.unknown(ctx
)
71 handler_diags
.append(str(d
))
74 ctx
.attach_diagnostic_handler(handler
)
77 Attribute
.parse("not an attr", ctx
)
78 except MLIRError
as e
:
79 # CHECK: emit_error_diagnostics=False:
80 # CHECK: e.error_diagnostics: ['expected attribute value']
81 # CHECK: handler_diags: []
82 print(f
"emit_error_diagnostics=False:")
83 print(f
"e.error_diagnostics: {[str(diag) for diag in e.error_diagnostics]}")
84 print(f
"handler_diags: {handler_diags}")
86 ctx
.emit_error_diagnostics
= True
88 Attribute
.parse("not an attr", ctx
)
89 except MLIRError
as e
:
90 # CHECK: emit_error_diagnostics=True:
91 # CHECK: e.error_diagnostics: []
92 # CHECK: handler_diags: ['expected attribute value']
93 print(f
"emit_error_diagnostics=True:")
94 print(f
"e.error_diagnostics: {[str(diag) for diag in e.error_diagnostics]}")
95 print(f
"handler_diags: {handler_diags}")