OlivierNicole / ocaml

The core OCaml system: compilers, runtime system, base libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segfault when quoting local variable in the toplevel

OlivierNicole opened this issue · comments

# let x = 42;;
val x : int = 42
# macro y () = <<x>>;;
macro y : unit -> int expr = <fun>
# y ();;;
- : int expr = << y.x(*0*) >>
# macro y = <<x>>;;
Segmentation fault (core dumped).

Precisions:

  • happens when the toplevel attempts to print the underlying AST in the quote
  • as shown in the example the segfault disappears when the quote is under lambda
  • the macro definition and its application to a path do not generate a segfault
  • no segfault happens when quoting a global instead of local identifier
  • no segfault happens when running the same code with ocamlc
  • no segfault happens when this code is passed as a file argument to ocaml.

Lambda code output (but recall that the segfault does not happen when executing the lambda, but later):

(seq 0a (makearray[addr]))
(let (x/1290 =[int] 42) (apply (field 1 (global Toploop!)) 0 "x" x/1290))
(let
  (y/1291 =a
     (function path/1292
       (apply (field 1 (field 11 (global ^CamlinternalQuote!)))
         (apply (field 1 (field 0 (global ^CamlinternalQuote!)))
           "\132\149\166\190\000\000\000\025\000\000\000\004\000\000\000\019\000\000\000\017\176\192,//toplevel//A@L\192\004\002A@M@")
         (apply (field 1 (field 4 (global ^CamlinternalQuote!))) path/1292
           "x" 0))))
  (seq (apply (field 1 (global Toploop!)) 1 "y" y/1291) (makearray[addr])))
(let
  (x/1290 = (apply (field 0 (global Toploop!)) 0 "x")
   y/1291 =a (makeblock 0 x/1290))
  (apply (field 1 (global Toploop!)) 0 "y" y/1291))

Fixed by 86ebc3c. The REPL printing code passed a Longident.t to the macro instead of a Longident.t loc.