MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / libcall_function

Function libcall_function

cranelift/jit/tests/basic.rs:150–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

148
149#[test]
150fn libcall_function() {
151 let Some(isa) = isa() else {
152 return;
153 };
154 let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names()));
155
156 let sig = Signature {
157 params: vec![],
158 returns: vec![],
159 call_conv: CallConv::SystemV,
160 };
161
162 let func_id = module
163 .declare_function("function", Linkage::Local, &sig)
164 .unwrap();
165
166 let mut ctx = Context::new();
167 ctx.func = Function::with_name_signature(UserFuncName::user(0, func_id.as_u32()), sig);
168
169 let mut func_ctx = FunctionBuilderContext::new();
170 {
171 let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
172 let block = bcx.create_block();
173 bcx.switch_to_block(block);
174
175 let int = module.target_config().pointer_type();
176 let zero = bcx.ins().iconst(I16, 0);
177 let size = bcx.ins().iconst(int, 10);
178
179 let mut signature = module.make_signature();
180 signature.params.push(AbiParam::new(int));
181 signature.returns.push(AbiParam::new(int));
182 let callee = module
183 .declare_function("malloc", Linkage::Import, &signature)
184 .expect("declare malloc function");
185 let local_callee = module.declare_func_in_func(callee, &mut bcx.func);
186 let argument_exprs = vec![size];
187 let call = bcx.ins().call(local_callee, &argument_exprs);
188 let buffer = bcx.inst_results(call)[0];
189
190 bcx.call_memset(module.target_config(), buffer, zero, size);
191
192 bcx.ins().return_(&[]);
193 }
194
195 module
196 .define_function_with_control_plane(func_id, &mut ctx, &mut Default::default())
197 .unwrap();
198
199 module.finalize_definitions().unwrap();
200}
201
202// This used to cause UB. See https://github.com/bytecodealliance/wasmtime/issues/7918.
203#[test]

Callers

nothing calls this directly

Calls 15

isaFunction · 0.85
default_libcall_namesFunction · 0.85
create_blockMethod · 0.80
switch_to_blockMethod · 0.80
call_memsetMethod · 0.80
finalize_definitionsMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
declare_functionMethod · 0.45
as_u32Method · 0.45
pointer_typeMethod · 0.45
target_configMethod · 0.45

Tested by

no test coverage detected