From c8d1da1e0d209f52476e2c608c5e5a2971696903 Mon Sep 17 00:00:00 2001 From: Timotej Kapus Date: Thu, 18 Jul 2019 05:53:34 -0700 Subject: [PATCH] [sledge] Fix __llair_alloc Summary: `__llair_alloc` is meant to be a drop-in non-failing replacement for `mallco`. Currently `__llair_alloc(1)` allocates 8 bytes instead of 1 as `malloc(1)` would. This is because handling of `__llair_alloc` was merged with handling of `new`. This patch reverts changes to handling of `new` in D15778817 and adds a new case for `__llair_alloc`. Reviewed By: jvillard Differential Revision: D16356865 fbshipit-source-id: 3878d87c3 --- sledge/src/llair/frontend.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sledge/src/llair/frontend.ml b/sledge/src/llair/frontend.ml index 6e237d51f..5a8243c07 100644 --- a/sledge/src/llair/frontend.ml +++ b/sledge/src/llair/frontend.ml @@ -943,10 +943,7 @@ let xlate_instr : | ["__llair_throw"] -> let exc = xlate_value x (Llvm.operand instr 0) in emit_term ~prefix:(pop loc) (Llair.Term.throw ~exc ~loc) - | ["_Znwm" (* operator new(size_t num) *)] - |["__llair_alloc" (* void* __llair_alloc(unsigned size) *)] - |[ "_ZnwmSt11align_val_t" - (* operator new(unsigned long, std::align_val_t) *) ] -> + | ["__llair_alloc" (* void* __llair_alloc(unsigned size) *)] -> let reg = xlate_name instr in let num_operand = Llvm.operand instr 0 in let num = @@ -954,6 +951,13 @@ let xlate_instr : (xlate_value x num_operand) ~src:(xlate_type x (Llvm.type_of num_operand)) in + let len = Exp.integer (Z.of_int 1) Typ.siz in + emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc) + | ["_Znwm" (* operator new(size_t num) *)] + |[ "_ZnwmSt11align_val_t" + (* operator new(unsigned long, std::align_val_t) *) ] -> + let reg = xlate_name instr in + let num = xlate_value x (Llvm.operand instr 0) in let llt = Llvm.type_of instr in let len = Exp.integer (Z.of_int (size_of x llt)) Typ.siz in emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)