Skip to content

Commit 24c459c

Browse files
committed
Use declare_anonymous_data for anonymous_str
1 parent 7c40338 commit 24c459c

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ pub(crate) fn codegen_operand<'tcx>(
870870
pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) {
871871
let location = fx.get_caller_location(span).load_scalar(fx);
872872

873-
let msg_ptr = fx.anonymous_str("assert", msg_str);
873+
let msg_ptr = fx.anonymous_str(msg_str);
874874
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
875875
let args = [msg_ptr, msg_len, location];
876876

src/common.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,12 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
345345
self.module.isa().triple()
346346
}
347347

348-
pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
349-
use std::collections::hash_map::DefaultHasher;
350-
use std::hash::{Hash, Hasher};
351-
352-
let mut hasher = DefaultHasher::new();
353-
msg.hash(&mut hasher);
354-
let msg_hash = hasher.finish();
348+
pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {
355349
let mut data_ctx = DataContext::new();
356350
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
357351
let msg_id = self
358352
.module
359-
.declare_data(&format!("__{}_{:08x}", prefix, msg_hash), Linkage::Local, false, false)
353+
.declare_anonymous_data(false, false)
360354
.unwrap();
361355

362356
// Ignore DuplicateDefinition error, as the data will be the same

src/trap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
2121
}
2222

2323
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, fx.symbol_name, msg);
24-
let msg_ptr = fx.anonymous_str("trap", &real_msg);
24+
let msg_ptr = fx.anonymous_str(&real_msg);
2525
fx.bcx.ins().call(puts, &[msg_ptr]);
2626
}
2727

0 commit comments

Comments
 (0)