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

+7-5
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

+1-1
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
};
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

+3-1
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

+11-5
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

-42
This file was deleted.

src/librustc/session/config.rs

+15
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

+4-11
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

+3
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

+1
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.

src/librustc_mir/interpret/place.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,28 @@ where
651651
use rustc::mir::PlaceBase;
652652

653653
let mut place_ty = match &place.base {
654-
PlaceBase::Local(mir::RETURN_PLACE) => match self.frame().return_place {
655-
Some(return_place) => {
656-
// We use our layout to verify our assumption; caller will validate
657-
// their layout on return.
658-
PlaceTy {
659-
place: *return_place,
660-
layout: self.layout_of(
661-
self.subst_from_frame_and_normalize_erasing_regions(
662-
self.frame().body.return_ty()
663-
)
664-
)?,
665-
}
654+
PlaceBase::Local(mir::RETURN_PLACE) => {
655+
// `return_place` has the *caller* layout, but we want to use our
656+
// `layout to verify our assumption. The caller will validate
657+
// their layout on return.
658+
PlaceTy {
659+
place: match self.frame().return_place {
660+
Some(p) => *p,
661+
// Even if we don't have a return place, we sometimes need to
662+
// create this place, but any attempt to read from / write to it
663+
// (even a ZST read/write) needs to error, so let us make this
664+
// a NULL place.
665+
//
666+
// FIXME: Ideally we'd make sure that the place projections also
667+
// bail out.
668+
None => Place::null(&*self),
669+
},
670+
layout: self.layout_of(
671+
self.subst_from_frame_and_normalize_erasing_regions(
672+
self.frame().body.return_ty()
673+
)
674+
)?,
666675
}
667-
None => throw_unsup!(InvalidNullPointerUsage),
668676
},
669677
PlaceBase::Local(local) => PlaceTy {
670678
// This works even for dead/uninitialized locals; we check further when writing
@@ -791,8 +799,8 @@ where
791799
// to handle padding properly, which is only correct if we never look at this data with the
792800
// wrong type.
793801

794-
let ptr = match self.check_mplace_access(dest, None)
795-
.expect("places should be checked on creation")
802+
// Invalid places are a thing: the return place of a diverging function
803+
let ptr = match self.check_mplace_access(dest, None)?
796804
{
797805
Some(ptr) => ptr,
798806
None => return Ok(()), // zero-sized access

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
2929
#![feature(stmt_expr_attributes)]
3030
#![feature(bool_to_option)]
3131
#![feature(trait_alias)]
32+
#![feature(matches_macro)]
3233

3334
#![recursion_limit="256"]
3435

src/librustc_mir/transform/check_consts/qualifs.rs

+5-32
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty::{self, Ty};
55
use rustc::hir::def_id::DefId;
66
use syntax_pos::DUMMY_SP;
77

8-
use super::{ConstKind, Item as ConstCx};
8+
use super::Item as ConstCx;
99

1010
pub fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> ConstQualifs {
1111
ConstQualifs {
@@ -33,9 +33,10 @@ pub trait Qualif {
3333
/// of the type.
3434
fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool;
3535

36-
fn in_static(_cx: &ConstCx<'_, 'tcx>, _def_id: DefId) -> bool {
37-
// FIXME(eddyb) should we do anything here for value properties?
38-
false
36+
fn in_static(cx: &ConstCx<'_, 'tcx>, def_id: DefId) -> bool {
37+
// `mir_const_qualif` does return the qualifs in the final value of a `static`, so we could
38+
// use value-based qualification here, but we shouldn't do this without a good reason.
39+
Self::in_any_value_of_ty(cx, cx.tcx.type_of(def_id))
3940
}
4041

4142
fn in_projection_structurally(
@@ -217,34 +218,6 @@ impl Qualif for HasMutInterior {
217218
rvalue: &Rvalue<'tcx>,
218219
) -> bool {
219220
match *rvalue {
220-
// Returning `true` for `Rvalue::Ref` indicates the borrow isn't
221-
// allowed in constants (and the `Checker` will error), and/or it
222-
// won't be promoted, due to `&mut ...` or interior mutability.
223-
Rvalue::Ref(_, kind, ref place) => {
224-
let ty = place.ty(cx.body, cx.tcx).ty;
225-
226-
if let BorrowKind::Mut { .. } = kind {
227-
// In theory, any zero-sized value could be borrowed
228-
// mutably without consequences.
229-
match ty.kind {
230-
// Inside a `static mut`, &mut [...] is also allowed.
231-
| ty::Array(..)
232-
| ty::Slice(_)
233-
if cx.const_kind == Some(ConstKind::StaticMut)
234-
=> {},
235-
236-
// FIXME(eddyb): We only return false for `&mut []` outside a const
237-
// context which seems unnecessary given that this is merely a ZST.
238-
| ty::Array(_, len)
239-
if len.try_eval_usize(cx.tcx, cx.param_env) == Some(0)
240-
&& cx.const_kind == None
241-
=> {},
242-
243-
_ => return true,
244-
}
245-
}
246-
}
247-
248221
Rvalue::Aggregate(ref kind, _) => {
249222
if let AggregateKind::Adt(def, ..) = **kind {
250223
if Some(def.did) == cx.tcx.lang_items().unsafe_cell_type() {

0 commit comments

Comments
 (0)