[sledge] Fix crashing frontned

Summary:
When LLVM is built with assertions, it crash
`add_sym` if you try to get the global scope of a non global value.

This patch special cases add_sym, to just do nothing when `llv` is
an `UndefValue`.

Also enhances debuging printout of transalte to include the number of
functions and globals.

Reviewed By: jvillard

Differential Revision: D15669447

fbshipit-source-id: 4b5483810
master
Timotej Kapus 6 years ago committed by Facebook Github Bot
parent 9ef992394c
commit 65f3b10c99

@ -72,14 +72,23 @@ let ( (scan_names_and_locs : Llvm.llmodule -> unit)
~col:(Llvm.get_debug_loc_column i)
in
let add_sym llv loc =
let next, void_tbl =
let scope =
let maybe_scope =
match Llvm.classify_value llv with
| Argument -> `Fun (Llvm.param_parent llv)
| BasicBlock -> `Fun (Llvm.block_parent (Llvm.block_of_value llv))
| Instruction _ -> `Fun (Llvm.block_parent (Llvm.instr_parent llv))
| _ -> `Mod (Llvm.global_parent llv)
| Argument -> Some (`Fun (Llvm.param_parent llv))
| BasicBlock ->
Some (`Fun (Llvm.block_parent (Llvm.block_of_value llv)))
| Instruction _ ->
Some (`Fun (Llvm.block_parent (Llvm.instr_parent llv)))
| GlobalVariable | Function -> Some (`Mod (Llvm.global_parent llv))
| UndefValue -> None
| _ ->
warn "Unexpected type of llv, might crash: %a" pp_llvalue llv () ;
Some (`Mod (Llvm.global_parent llv))
in
match maybe_scope with
| None -> ()
| Some scope ->
let next, void_tbl =
Hashtbl.find_or_add scope_tbl scope ~default:(fun () ->
(ref 0, Hashtbl.Poly.create ()) )
in
@ -103,7 +112,8 @@ let ( (scan_names_and_locs : Llvm.llmodule -> unit)
fname ^ ".void"
| Some count ->
Hashtbl.set void_tbl ~key:fname ~data:(count + 1) ;
String.concat_array [|fname; ".void."; Int.to_string count|] )
String.concat_array
[|fname; ".void."; Int.to_string count|] )
| _ -> (
match Llvm.value_name llv with
| "" ->
@ -1404,4 +1414,6 @@ let translate : string list -> Llair.t =
Llvm.dispose_module llmodule ;
Llair.mk ~globals ~functions
|>
[%Trace.retn fun {pf} _ -> pf ""]
[%Trace.retn fun {pf} _ ->
pf "number of globals %d, number of functions %d" (List.length globals)
(List.length functions)]

Loading…
Cancel
Save