Skip to content

Commit 362caf7

Browse files
committed
Sync from rust faae5f1
2 parents 29b2d42 + b2f6349 commit 362caf7

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

example/mini_core.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,36 @@ pub fn panic(_msg: &'static str) -> ! {
465465
}
466466
}
467467

468+
macro_rules! panic_const {
469+
($($lang:ident = $message:expr,)+) => {
470+
#[cfg(not(bootstrap))]
471+
pub mod panic_const {
472+
use super::*;
473+
474+
$(
475+
#[track_caller]
476+
#[lang = stringify!($lang)]
477+
pub fn $lang() -> ! {
478+
panic($message);
479+
}
480+
)+
481+
}
482+
}
483+
}
484+
485+
panic_const! {
486+
panic_const_add_overflow = "attempt to add with overflow",
487+
panic_const_sub_overflow = "attempt to subtract with overflow",
488+
panic_const_mul_overflow = "attempt to multiply with overflow",
489+
panic_const_div_overflow = "attempt to divide with overflow",
490+
panic_const_rem_overflow = "attempt to calculate the remainder with overflow",
491+
panic_const_neg_overflow = "attempt to negate with overflow",
492+
panic_const_shr_overflow = "attempt to shift right with overflow",
493+
panic_const_shl_overflow = "attempt to shift left with overflow",
494+
panic_const_div_by_zero = "attempt to divide by zero",
495+
panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero",
496+
}
497+
468498
#[lang = "panic_bounds_check"]
469499
#[track_caller]
470500
fn panic_bounds_check(index: usize, len: usize) -> ! {

src/base.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,14 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
372372
);
373373
}
374374
_ => {
375-
let msg_str = msg.description();
376-
codegen_panic(fx, msg_str, source_info);
375+
let location = fx.get_caller_location(source_info).load_scalar(fx);
376+
377+
codegen_panic_inner(
378+
fx,
379+
msg.panic_function(),
380+
&[location],
381+
Some(source_info.span),
382+
);
377383
}
378384
}
379385
}
@@ -957,20 +963,6 @@ pub(crate) fn codegen_operand<'tcx>(
957963
}
958964
}
959965

960-
pub(crate) fn codegen_panic<'tcx>(
961-
fx: &mut FunctionCx<'_, '_, 'tcx>,
962-
msg_str: &str,
963-
source_info: mir::SourceInfo,
964-
) {
965-
let location = fx.get_caller_location(source_info).load_scalar(fx);
966-
967-
let msg_ptr = fx.anonymous_str(msg_str);
968-
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
969-
let args = [msg_ptr, msg_len, location];
970-
971-
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, Some(source_info.span));
972-
}
973-
974966
pub(crate) fn codegen_panic_nounwind<'tcx>(
975967
fx: &mut FunctionCx<'_, '_, 'tcx>,
976968
msg_str: &str,

src/debuginfo/line_info.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ impl DebugContext {
8989
match &source_file.name {
9090
FileName::Real(path) => {
9191
let (dir_path, file_name) =
92-
split_path_dir_and_file(if self.should_remap_filepaths {
93-
path.remapped_path_if_available()
94-
} else {
95-
path.local_path_if_available()
96-
});
92+
split_path_dir_and_file(path.to_path(self.filename_display_preference));
9793
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
9894
let file_name = osstr_as_utf8_bytes(file_name);
9995

@@ -115,14 +111,7 @@ impl DebugContext {
115111
filename => {
116112
let dir_id = line_program.default_directory();
117113
let dummy_file_name = LineString::new(
118-
filename
119-
.display(if self.should_remap_filepaths {
120-
FileNameDisplayPreference::Remapped
121-
} else {
122-
FileNameDisplayPreference::Local
123-
})
124-
.to_string()
125-
.into_bytes(),
114+
filename.display(self.filename_display_preference).to_string().into_bytes(),
126115
line_program.encoding(),
127116
line_strings,
128117
);

src/debuginfo/mod.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) struct DebugContext {
4242
namespace_map: DefIdMap<UnitEntryId>,
4343
array_size_type: UnitEntryId,
4444

45-
should_remap_filepaths: bool,
45+
filename_display_preference: FileNameDisplayPreference,
4646
}
4747

4848
pub(crate) struct FunctionDebugContext {
@@ -84,22 +84,18 @@ impl DebugContext {
8484

8585
let mut dwarf = DwarfUnit::new(encoding);
8686

87-
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
87+
use rustc_session::config::RemapPathScopeComponents;
88+
89+
let filename_display_preference =
90+
tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
8891

8992
let producer = producer(tcx.sess);
90-
let comp_dir = tcx
91-
.sess
92-
.opts
93-
.working_dir
94-
.to_string_lossy(if should_remap_filepaths {
95-
FileNameDisplayPreference::Remapped
96-
} else {
97-
FileNameDisplayPreference::Local
98-
})
99-
.into_owned();
93+
let comp_dir =
94+
tcx.sess.opts.working_dir.to_string_lossy(filename_display_preference).to_string();
95+
10096
let (name, file_info) = match tcx.sess.local_crate_source_file() {
10197
Some(path) => {
102-
let name = path.to_string_lossy().into_owned();
98+
let name = path.to_string_lossy(filename_display_preference).to_string();
10399
(name, None)
104100
}
105101
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
@@ -156,7 +152,7 @@ impl DebugContext {
156152
stack_pointer_register,
157153
namespace_map: DefIdMap::default(),
158154
array_size_type,
159-
should_remap_filepaths,
155+
filename_display_preference,
160156
}
161157
}
162158

0 commit comments

Comments
 (0)