From 29d8f0894be047c3b1210e69bb87b6e12357b577 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 4 Oct 2018 18:56:35 -0400 Subject: [PATCH] Turn some asserts into runtime traps instead Unfortunately, we cannnot always rely on :invokes to have argument values that match the declared ssa types (e.g. if the :invoke is dynamically unreachable). Because of that, we cannot assert here, but must instead emit a runtime trap. --- src/codegen.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index aab4586e41b4d..506c4f94640d6 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2979,6 +2979,12 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_method_instance_ argvals[idx] = maybe_decay_untracked(boxed(ctx, arg)); } else if (et->isAggregateType()) { + if (!arg.ispointer()) { + // This can happen in dead code if there's a type mismatch + // Exit early + CreateTrap(ctx.builder); + return jl_cgval_t(); + } // can lazy load on demand, no copy needed assert(at == PointerType::get(et, AddressSpace::Derived)); assert(arg.ispointer()); @@ -2987,7 +2993,13 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_method_instance_ } else { assert(at == et); - argvals[idx] = emit_unbox(ctx, et, arg, jt); + Value *val = emit_unbox(ctx, et, arg, jt); + if (!val) { + // There was a type mismatch of some sort - exit early + CreateTrap(ctx.builder); + return jl_cgval_t(); + } + argvals[idx] = val; } idx++; }