[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
master
Timotej Kapus 5 years ago committed by Facebook Github Bot
parent af12e55344
commit c8d1da1e0d

@ -943,10 +943,7 @@ let xlate_instr :
| ["__llair_throw"] -> | ["__llair_throw"] ->
let exc = xlate_value x (Llvm.operand instr 0) in let exc = xlate_value x (Llvm.operand instr 0) in
emit_term ~prefix:(pop loc) (Llair.Term.throw ~exc ~loc) emit_term ~prefix:(pop loc) (Llair.Term.throw ~exc ~loc)
| ["_Znwm" (* operator new(size_t num) *)] | ["__llair_alloc" (* void* __llair_alloc(unsigned size) *)] ->
|["__llair_alloc" (* void* __llair_alloc(unsigned size) *)]
|[ "_ZnwmSt11align_val_t"
(* operator new(unsigned long, std::align_val_t) *) ] ->
let reg = xlate_name instr in let reg = xlate_name instr in
let num_operand = Llvm.operand instr 0 in let num_operand = Llvm.operand instr 0 in
let num = let num =
@ -954,6 +951,13 @@ let xlate_instr :
(xlate_value x num_operand) (xlate_value x num_operand)
~src:(xlate_type x (Llvm.type_of num_operand)) ~src:(xlate_type x (Llvm.type_of num_operand))
in 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 llt = Llvm.type_of instr in
let len = Exp.integer (Z.of_int (size_of x llt)) Typ.siz in let len = Exp.integer (Z.of_int (size_of x llt)) Typ.siz in
emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc) emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)

Loading…
Cancel
Save