From e45a05a57400f6330a90efab913821b8ed4a327a Mon Sep 17 00:00:00 2001 From: Timotej Kapus Date: Mon, 3 Jun 2019 05:27:51 -0700 Subject: [PATCH] [sledge] fix LLVM assertion failure in xlate_global Summary: LLVM.global_initializer casues a cast assertion failure if the value passed to it is not a GlobalVariable. So we first check if it is a GlobalVariable and only then ask for an initiliazer. This is hidden if LLVM is built without assertions. Reviewed By: jberdine Differential Revision: D15601632 fbshipit-source-id: e9db23a12 --- sledge/src/llair/frontend.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sledge/src/llair/frontend.ml b/sledge/src/llair/frontend.ml index fb21536c4..c6eb6c29a 100644 --- a/sledge/src/llair/frontend.ml +++ b/sledge/src/llair/frontend.ml @@ -588,11 +588,14 @@ and xlate_global : x -> Llvm.llvalue -> Global.t = its own initializer *) Hashtbl.set memo_global ~key:llg ~data:(Global.mk g typ loc) ; let init = - match (Llvm.classify_value llg, Llvm.global_initializer llg) with - | GlobalVariable, Some llinit -> - let siz = size_of x (Llvm.element_type llt) in - let init = xlate_value x llinit in - Some (init, siz) + match Llvm.classify_value llg with + | GlobalVariable -> ( + match Llvm.global_initializer llg with + | Some llinit -> + let siz = size_of x (Llvm.element_type llt) in + let init = xlate_value x llinit in + Some (init, siz) + | _ -> None ) | _ -> None in Global.mk ?init g typ loc