Skip to content

Commit

Permalink
flambda-backend: Correctly stack debuginfo for inlined body in classi…
Browse files Browse the repository at this point in the history
…c mode (#1152)
  • Loading branch information
Gbury authored Mar 13, 2023
1 parent 6733de6 commit 577410e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 8 deletions.
22 changes: 22 additions & 0 deletions testsuite/tests/backtrace-multifiles/foo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

let[@inline never] print s = (print_endline[@inlined never]) s

let[@inline] print_stack () =
let st = Printexc.get_callstack 100 in
(Printexc.print_raw_backtrace[@inlined never]) stdout st

let[@inline] f s =
print_stack ();
print s

let[@inline] g s =
let s = (String.cat[@inlined never]) s " !" in
f s;
print_stack ();
print "end of g"

let[@inline] h s =
g s;
print_stack ();
print "end of h"

82 changes: 82 additions & 0 deletions testsuite/tests/backtrace-multifiles/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(* TEST_BELOW *)

let[@inline never] test s =
let s' = (String.cat[@inlined never]) "! " s in
(Foo.h[@inlined]) s'; (* CR gbury: remove [@inlined], cf #1199 *)
(Foo.print_stack[@inlined]) (); (* CR gbury: remove [@inlined], cf #1199 *)
(print_endline[@inlined never]) "end of test"

let () =
Printexc.record_backtrace true;
test "foobar"

(* This test aims at checking that backtraces are correct after inlining,
particularly after inlining of functions from other files, and
furthermore from other files compiled with different optimization options.
We therefore define quite a few functions (in `foo.ml`) that use one
another (with a lot of inlining). Additionally, we also print
stack/backtraces after an inlined function (in the `test` function above),
to ensure that we do not wrongly propagate debuginfos past the function
call. *)

(* TEST
readonly_files ="foo.ml"
* setup-ocamlopt.opt-build-env
compiler_directory_suffix = ".O3"
** ocamlopt.opt
module = "foo.ml"
flags = "-g -O3"
*** ocamlopt.opt
module = "main.ml"
flags = "-g -O3"
**** ocamlopt.opt
module = ""
all_modules = "foo.cmx main.cmx"
***** run
****** check-program-output
* setup-ocamlopt.opt-build-env
compiler_directory_suffix = ".Oclassic"
** ocamlopt.opt
module = "foo.ml"
flags = "-g -Oclassic"
*** ocamlopt.opt
module = "main.ml"
flags = "-g -Oclassic"
**** ocamlopt.opt
module = ""
all_modules = "foo.cmx main.cmx"
***** run
****** check-program-output
* setup-ocamlopt.opt-build-env
compiler_directory_suffix = ".O3-Oclassic"
** ocamlopt.opt
module = "foo.ml"
flags = "-g -O3"
*** ocamlopt.opt
module = "main.ml"
flags = "-g -Oclassic"
**** ocamlopt.opt
module = ""
all_modules = "foo.cmx main.cmx"
***** run
****** check-program-output
* setup-ocamlopt.opt-build-env
compiler_directory_suffix = ".Oclassic-O3"
** ocamlopt.opt
module = "foo.ml"
flags = "-g -Oclassic"
*** ocamlopt.opt
module = "main.ml"
flags = "-g -O3"
**** ocamlopt.opt
module = ""
all_modules = "foo.cmx main.cmx"
***** run
****** check-program-output
*)
22 changes: 22 additions & 0 deletions testsuite/tests/backtrace-multifiles/main.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Raised by primitive operation at Foo.print_stack in file "foo.ml" (inlined), line 5, characters 11-37
Called from Foo.f in file "foo.ml" (inlined), line 9, characters 2-16
Called from Foo.g in file "foo.ml" (inlined), line 14, characters 2-5
Called from Foo.h in file "foo.ml" (inlined), line 19, characters 2-5
Called from Main.test in file "main.ml", line 5, characters 2-22
Called from Main in file "main.ml", line 11, characters 2-15
! foobar !
Raised by primitive operation at Foo.print_stack in file "foo.ml" (inlined), line 5, characters 11-37
Called from Foo.g in file "foo.ml" (inlined), line 15, characters 2-16
Called from Foo.h in file "foo.ml" (inlined), line 19, characters 2-5
Called from Main.test in file "main.ml", line 5, characters 2-22
Called from Main in file "main.ml", line 11, characters 2-15
end of g
Raised by primitive operation at Foo.print_stack in file "foo.ml" (inlined), line 5, characters 11-37
Called from Foo.h in file "foo.ml" (inlined), line 20, characters 2-16
Called from Main.test in file "main.ml", line 5, characters 2-22
Called from Main in file "main.ml", line 11, characters 2-15
end of h
Raised by primitive operation at Foo.print_stack in file "foo.ml" (inlined), line 5, characters 11-37
Called from Main.test in file "main.ml", line 6, characters 2-32
Called from Main in file "main.ml", line 11, characters 2-15
end of test
3 changes: 3 additions & 0 deletions testsuite/tests/backtrace/inline_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* native
ocamlopt_flags = "-O3"
compiler_directory_suffix = ".O3"
* native
ocamlopt_flags = "-Oclassic"
compiler_directory_suffix = ".Oclassic"
*)

(* A test for inlined stack backtraces *)
Expand Down
10 changes: 5 additions & 5 deletions testsuite/tests/backtrace/inline_test.reference
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "inline_test.ml", line 14, characters 2-24
File "inline_test.ml", line 17, characters 2-5
File "inline_test.ml", line 20, characters 12-17
File "inline_test.ml", line 23, characters 5-8
File "inline_test.ml", line 26, characters 2-6
File "inline_test.ml", line 17, characters 2-24
File "inline_test.ml", line 20, characters 2-5
File "inline_test.ml", line 23, characters 12-17
File "inline_test.ml", line 26, characters 5-8
File "inline_test.ml", line 29, characters 2-6
3 changes: 3 additions & 0 deletions testsuite/tests/backtrace/inline_traversal_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* native
ocamlopt_flags = "-O3"
compiler_directory_suffix = ".O3"
* native
ocamlopt_flags = "-Oclassic"
compiler_directory_suffix = ".Oclassic"
*)

(* A test for inlined stack backtraces *)
Expand Down
6 changes: 3 additions & 3 deletions testsuite/tests/backtrace/inline_traversal_test.reference
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File inline_traversal_test.ml:14, raise
File inline_traversal_test.ml:17
File inline_traversal_test.ml:17, raise
File inline_traversal_test.ml:20
File inline_traversal_test.ml:23
File inline_traversal_test.ml:27
File inline_traversal_test.ml:26
File inline_traversal_test.ml:30

0 comments on commit 577410e

Please sign in to comment.