@@ -84,6 +84,9 @@ def find_span(m):
8484
8585
8686def test_llvm_ir_debug_info ():
87+ """
88+ Check that the right amount of debug locations are present
89+ """
8790 MyModule = _module ()
8891 with tvm .transform .PassContext (opt_level = 3 , config = {"tir.enable_debug" : True }):
8992 runtime_module = tvm .build (MyModule , target = "llvm" )
@@ -94,5 +97,28 @@ def test_llvm_ir_debug_info():
9497 assert len (locations ) == 34
9598
9699
100+ def test_llvm_ir_debug_accuracy ():
101+ """
102+ Check that the debug location on an assert is correct
103+ """
104+ MyModule = _module ()
105+ with tvm .transform .PassContext (opt_level = 3 , config = {"tir.enable_debug" : True }):
106+ runtime_module = tvm .build (MyModule , target = "llvm" )
107+ source = runtime_module .get_source ()
108+ locations = find_di_locations (source )
109+
110+ # Find the 'assert' from MyModule
111+ debug_dir_match = re .search (
112+ r"tail call void %0\(i8\* getelementptr inbounds .* !dbg !(\d+)\n" , source
113+ )
114+
115+ # Extract out the debug directive line
116+ directive_idx = debug_dir_match .groups ()[0 ]
117+
118+ # Check that it matches the expected line number (in main.tir)
119+ debug_line_no = int (locations [directive_idx ])
120+ assert debug_line_no == 42
121+
122+
97123if __name__ == "__main__" :
98124 tvm .testing .main ()
0 commit comments