Skip to content

Commit 96414a8

Browse files
committed
Sync from rust a84ab0ce6c4557a2f01a3a6c3fdb0f92098db78d
2 parents 8dab8de + de58bdc commit 96414a8

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/allocator.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,34 @@ fn codegen_inner(
8484
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
8585
);
8686

87-
let data_id = module
88-
.declare_data(
89-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
90-
Linkage::Export,
91-
false,
92-
false,
93-
)
94-
.unwrap();
95-
let mut data = DataDescription::new();
96-
data.set_align(1);
97-
let val = oom_strategy.should_panic();
98-
data.define(Box::new([val]));
99-
module.define_data(data_id, &data).unwrap();
87+
{
88+
let sig = Signature {
89+
call_conv: module.target_config().default_call_conv,
90+
params: vec![],
91+
returns: vec![AbiParam::new(types::I8)],
92+
};
93+
let func_id = module
94+
.declare_function(
95+
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
96+
Linkage::Export,
97+
&sig,
98+
)
99+
.unwrap();
100+
let mut ctx = Context::new();
101+
ctx.func.signature = sig;
102+
{
103+
let mut func_ctx = FunctionBuilderContext::new();
104+
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
105+
106+
let block = bcx.create_block();
107+
bcx.switch_to_block(block);
108+
let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64);
109+
bcx.ins().return_(&[value]);
110+
bcx.seal_all_blocks();
111+
bcx.finalize();
112+
}
113+
module.define_function(func_id, &mut ctx).unwrap();
114+
}
100115

101116
{
102117
let sig = Signature {

0 commit comments

Comments
 (0)