Skip to content

Commit 4af3ee8

Browse files
committed
Auto merge of #66950 - RalfJung:rollup-12d0zx8, r=RalfJung
Rollup of 5 pull requests Successful merges: - #66245 (Conditional compilation for sanitizers) - #66654 (Handle const-checks for `&mut` outside of `HasMutInterior`) - #66822 (libunwind_panic: adjust miri panic hack) - #66827 (handle diverging functions forwarding their return place) - #66834 (rustbuild fixes) Failed merges: r? @ghost
2 parents f5c81e0 + 910e83e commit 4af3ee8

File tree

24 files changed

+292
-261
lines changed

24 files changed

+292
-261
lines changed

src/bootstrap/bootstrap.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ def build_bootstrap(self):
643643
env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \
644644
(os.pathsep + env["LIBRARY_PATH"]) \
645645
if "LIBRARY_PATH" in env else ""
646-
env["RUSTFLAGS"] = "-Cdebuginfo=2 "
646+
# preserve existing RUSTFLAGS
647+
env.setdefault("RUSTFLAGS", "")
648+
env["RUSTFLAGS"] += " -Cdebuginfo=2"
647649

648650
build_section = "target.{}".format(self.build_triple())
649651
target_features = []
@@ -652,13 +654,13 @@ def build_bootstrap(self):
652654
elif self.get_toml("crt-static", build_section) == "false":
653655
target_features += ["-crt-static"]
654656
if target_features:
655-
env["RUSTFLAGS"] += "-C target-feature=" + (",".join(target_features)) + " "
657+
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
656658
target_linker = self.get_toml("linker", build_section)
657659
if target_linker is not None:
658-
env["RUSTFLAGS"] += "-C linker=" + target_linker + " "
659-
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes "
660+
env["RUSTFLAGS"] += " -C linker=" + target_linker
661+
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
660662
if self.get_toml("deny-warnings", "rust") != "false":
661-
env["RUSTFLAGS"] += "-Dwarnings "
663+
env["RUSTFLAGS"] += " -Dwarnings"
662664

663665
env["PATH"] = os.path.join(self.bin_root(), "bin") + \
664666
os.pathsep + env["PATH"]

src/bootstrap/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ install!((self, builder, _config),
260260
};
261261
Rustc, "src/librustc", true, only_hosts: true, {
262262
builder.ensure(dist::Rustc {
263-
compiler: self.compiler,
263+
compiler: builder.compiler(builder.top_stage, self.target),
264264
});
265265
install_rustc(builder, self.compiler.stage, self.target);
266266
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# `cfg_sanitize`
2+
3+
The tracking issue for this feature is: [#39699]
4+
5+
[#39699]: https://github.com/rust-lang/rust/issues/39699
6+
7+
------------------------
8+
9+
The `cfg_sanitize` feature makes it possible to execute different code
10+
depending on whether a particular sanitizer is enabled or not.
11+
12+
## Examples
13+
14+
``` rust
15+
#![feature(cfg_sanitize)]
16+
17+
#[cfg(sanitize = "thread")]
18+
fn a() {
19+
// ...
20+
}
21+
22+
#[cfg(not(sanitize = "thread"))]
23+
fn a() {
24+
// ...
25+
}
26+
27+
fn b() {
28+
if cfg!(sanitize = "leak") {
29+
// ...
30+
} else {
31+
// ...
32+
}
33+
}
34+
35+
```
36+

src/libcore/intrinsics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,11 @@ extern "rust-intrinsic" {
13481348
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
13491349

13501350
/// Internal hook used by Miri to implement unwinding.
1351+
/// Compiles to a NOP during non-Miri codegen.
1352+
///
13511353
/// Perma-unstable: do not use
13521354
#[cfg(not(bootstrap))]
1353-
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> !;
1355+
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
13541356
}
13551357

13561358
// Some functions are defined here because they accidentally got made

src/libpanic_unwind/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use core::raw;
3636
use core::panic::BoxMeUp;
3737

3838
cfg_if::cfg_if! {
39-
if #[cfg(miri)] {
40-
#[path = "miri.rs"]
41-
mod imp;
42-
} else if #[cfg(target_os = "emscripten")] {
39+
if #[cfg(target_os = "emscripten")] {
4340
#[path = "emcc.rs"]
4441
mod imp;
4542
} else if #[cfg(target_arch = "wasm32")] {
@@ -94,5 +91,14 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
9491
#[unwind(allowed)]
9592
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
9693
let payload = payload as *mut &mut dyn BoxMeUp;
97-
imp::panic(Box::from_raw((*payload).take_box()))
94+
let payload = (*payload).take_box();
95+
96+
// Miri panic support: cfg'd out of normal builds just to be sure.
97+
// When going through normal codegen, `miri_start_panic` is a NOP, so the
98+
// Miri-enabled sysroot still supports normal unwinding. But when executed in
99+
// Miri, this line initiates unwinding.
100+
#[cfg(miri)]
101+
core::intrinsics::miri_start_panic(payload);
102+
103+
imp::panic(Box::from_raw(payload))
98104
}

src/libpanic_unwind/miri.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/librustc/session/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ pub enum Sanitizer {
4747
Thread,
4848
}
4949

50+
impl fmt::Display for Sanitizer {
51+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52+
match *self {
53+
Sanitizer::Address => "address".fmt(f),
54+
Sanitizer::Leak => "leak".fmt(f),
55+
Sanitizer::Memory => "memory".fmt(f),
56+
Sanitizer::Thread => "thread".fmt(f),
57+
}
58+
}
59+
}
60+
5061
impl FromStr for Sanitizer {
5162
type Err = ();
5263
fn from_str(s: &str) -> Result<Sanitizer, ()> {
@@ -1580,6 +1591,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
15801591
}
15811592
}
15821593
}
1594+
if let Some(s) = &sess.opts.debugging_opts.sanitizer {
1595+
let symbol = Symbol::intern(&s.to_string());
1596+
ret.insert((sym::sanitize, Some(symbol)));
1597+
}
15831598
if sess.opts.debug_assertions {
15841599
ret.insert((Symbol::intern("debug_assertions"), None));
15851600
}

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
528528
_ => FnAbi::new(&bx, sig, &extra_args)
529529
};
530530

531-
// This should never be reachable at runtime:
532-
// We should only emit a call to this intrinsic in #[cfg(miri)] mode,
533-
// which means that we will never actually use the generate object files
534-
// (we will just be interpreting the MIR)
535-
//
536-
// Note that we still need to be able to codegen *something* for this intrisnic:
537-
// Miri currently uses Xargo to build a special libstd. As a side effect,
538-
// we generate normal object files for libstd - while these are never used,
539-
// we still need to be able to build them.
531+
// For normal codegen, this Miri-specific intrinsic is just a NOP.
540532
if intrinsic == Some("miri_start_panic") {
541-
bx.abort();
542-
bx.unreachable();
533+
let target = destination.as_ref().unwrap().1;
534+
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
535+
helper.funclet_br(self, &mut bx, target);
543536
return;
544537
}
545538

src/librustc_feature/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ declare_features! (
524524
/// Allows the use of `if` and `match` in constants.
525525
(active, const_if_match, "1.41.0", Some(49146), None),
526526

527+
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
528+
(active, cfg_sanitize, "1.41.0", Some(39699), None),
529+
527530
// -------------------------------------------------------------------------
528531
// feature-group-end: actual feature gates
529532
// -------------------------------------------------------------------------

src/librustc_feature/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const GATED_CFGS: &[GatedCfg] = &[
2525
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
2626
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
2727
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
28+
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
2829
];
2930

3031
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.

0 commit comments

Comments
 (0)