Merge pull request #2990 from rtfeldman/llvm-wasm-string-literal

keep strings on the stack on 32-bit targets
This commit is contained in:
Brian Carroll 2022-05-03 01:56:52 -05:00 committed by GitHub
commit de7fbc3fb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -806,20 +806,24 @@ pub fn build_exp_literal<'a, 'ctx, 'env>(
Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(), Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(),
Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(), Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(),
Str(str_literal) => { Str(str_literal) => {
let global = if str_literal.len() < env.small_str_bytes() as usize { if str_literal.len() < env.small_str_bytes() as usize {
match env.small_str_bytes() { match env.small_str_bytes() {
24 => small_str_ptr_width_8(env, parent, str_literal), 24 => small_str_ptr_width_8(env, parent, str_literal).into(),
12 => small_str_ptr_width_4(env, parent, str_literal), 12 => small_str_ptr_width_4(env, parent, str_literal).into(),
_ => unreachable!("incorrect small_str_bytes"), _ => unreachable!("incorrect small_str_bytes"),
} }
} else { } else {
let ptr = define_global_str_literal_ptr(env, *str_literal); let ptr = define_global_str_literal_ptr(env, *str_literal);
let number_of_elements = env.ptr_int().const_int(str_literal.len() as u64, false); let number_of_elements = env.ptr_int().const_int(str_literal.len() as u64, false);
const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements) let alloca =
}; const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements);
global.into() match env.target_info.ptr_width() {
PtrWidth::Bytes4 => env.builder.build_load(alloca, "load_const_str"),
PtrWidth::Bytes8 => alloca.into(),
}
}
} }
} }
} }