Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #77061

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f05b47c
Don't download/sync llvm-project submodule if download-ci-llvm is set
est31 Sep 18, 2020
d4039c5
wip emit errors during AbstractConst building
lcnr Sep 19, 2020
30cbc97
words
lcnr Sep 19, 2020
eb3eb85
[mir-opt] Introduce a new flag to enable experimental/unsound mir opts
wesleywiser Sep 19, 2020
3498511
Remove unnecessary -Zunsound-mir-opts uses in tests
wesleywiser Sep 19, 2020
db74e1f
Add cfg(target_has_atomic_equal_alignment).
m-ou-se Sep 20, 2020
9e3f94d
Don't unwrap but report a fatal error for TargetDataLayout::parse.
m-ou-se Sep 20, 2020
af56ad7
Add feature gate ui test for cfg(target_has_atomic_load_store).
m-ou-se Sep 20, 2020
54fdf54
Add feature gate ui test for cfg(target_has_atomic_equal_alignment).
m-ou-se Sep 20, 2020
668225d
Revert "Revert adding Atomic::from_mut."
m-ou-se Sep 21, 2020
7a04ff6
Gate Atomic::from_mut on cfg(target_has_atomic_equal_alignment).
m-ou-se Sep 20, 2020
5d6f1a1
Move `use align_of` in atomic.rs into the places where it is used.
m-ou-se Sep 21, 2020
e734733
Record `tcx.def_span` instead of `item.span` in crate metadata
Aaron1011 Sep 19, 2020
bcc1d56
Test that AtomicU64::from_mut is not available on x86 linux.
m-ou-se Sep 21, 2020
7a02ebd
bless tests
lcnr Sep 21, 2020
9a493ce
add test for closures in abstract consts
lcnr Sep 21, 2020
2f893e4
review
lcnr Sep 21, 2020
4a6bc77
Liballoc bench vec use mem take not replace
pickfire Sep 22, 2020
731113b
Miri: more informative deallocation error messages
RalfJung Sep 22, 2020
0082d20
Typo fix: "satsify" -> "satisfy"
follower Sep 22, 2020
05c3a2b
Add #[track_caller] to more panicking Cell functions
est31 Sep 22, 2020
3ee08ff
Rollup merge of #76864 - est31:downloaded_llvm_no_clone_sources, r=Ma…
Dylan-DPC Sep 22, 2020
0b0a98a
Rollup merge of #76898 - Aaron1011:fix/item-def-span, r=oli-obk
Dylan-DPC Sep 22, 2020
aa2dcb3
Rollup merge of #76899 - wesleywiser:experimental_unsound_mir_opts_fl…
Dylan-DPC Sep 22, 2020
1f8002d
Rollup merge of #76939 - lcnr:const-evaluatable-cont, r=oli-obk
Dylan-DPC Sep 22, 2020
ca93c3e
Rollup merge of #76965 - fusion-engineering-forks:fix-atomic-from-mut…
Dylan-DPC Sep 22, 2020
a66e104
Rollup merge of #77044 - pickfire:patch-4, r=jyn514
Dylan-DPC Sep 22, 2020
f60a8cf
Rollup merge of #77047 - RalfJung:miri-dealloc, r=oli-obk
Dylan-DPC Sep 22, 2020
97ef2b5
Rollup merge of #77050 - follower:patch-1, r=oli-obk
Dylan-DPC Sep 22, 2020
ab76650
Rollup merge of #77055 - est31:more_track_caller, r=Mark-Simulacrum
Dylan-DPC Sep 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const GATED_CFGS: &[GatedCfg] = &[
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(
sym::target_has_atomic_equal_alignment,
sym::cfg_target_has_atomic,
cfg_fn!(cfg_target_has_atomic),
),
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
];
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{AtomicCell, Lock, LockGuard, Lrc, OnceCell};
use rustc_errors::ErrorReported;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive};
use rustc_hir as hir;
Expand Down Expand Up @@ -1201,13 +1202,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
&self,
tcx: TyCtxt<'tcx>,
id: DefIndex,
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
self.root
.tables
.mir_abstract_consts
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
.map_or(None, |v| Some(v.decode((self, tcx))))
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
}

fn get_unused_generic_params(&self, id: DefIndex) -> FiniteBitSet<u32> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ impl EncodeContext<'a, 'tcx> {
}

let abstract_const = self.tcx.mir_abstract_const(def_id);
if let Some(abstract_const) = abstract_const {
if let Ok(Some(abstract_const)) = abstract_const {
record!(self.tables.mir_abstract_consts[def_id.to_def_id()] <- abstract_const);
}
}
Expand Down Expand Up @@ -1300,7 +1300,7 @@ impl EncodeContext<'a, 'tcx> {
});
record!(self.tables.visibility[def_id] <-
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
record!(self.tables.span[def_id] <- item.span);
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
record!(self.tables.attributes[def_id] <- item.attrs);
// FIXME(eddyb) there should be a nicer way to do this.
match item.kind {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub enum ErrorHandled {
TooGeneric,
}

impl From<ErrorReported> for ErrorHandled {
fn from(err: ErrorReported) -> ErrorHandled {
ErrorHandled::Reported(err)
}
}

CloneTypeFoldableAndLiftImpls! {
ErrorHandled,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ rustc_queries! {
/// Try to build an abstract representation of the given constant.
query mir_abstract_const(
key: DefId
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
desc {
|tcx| "building an abstract representation for {}", tcx.def_path_str(key),
}
}
/// Try to build an abstract representation of the given constant.
query mir_abstract_const_of_const_arg(
key: (LocalDefId, DefId)
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
desc {
|tcx|
"building an abstract representation for the const argument {}",
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_mir/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
None => {
// Deallocating global memory -- always an error
return Err(match self.tcx.get_global_alloc(ptr.alloc_id) {
Some(GlobalAlloc::Function(..)) => err_ub_format!("deallocating a function"),
Some(GlobalAlloc::Function(..)) => {
err_ub_format!("deallocating {}, which is a function", ptr.alloc_id)
}
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
err_ub_format!("deallocating static memory")
err_ub_format!("deallocating {}, which is static memory", ptr.alloc_id)
}
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
}
Expand All @@ -297,15 +299,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {

if alloc_kind != kind {
throw_ub_format!(
"deallocating {} memory using {} deallocation operation",
"deallocating {}, which is {} memory, using {} deallocation operation",
ptr.alloc_id,
alloc_kind,
kind
);
}
if let Some((size, align)) = old_size_and_align {
if size != alloc.size || align != alloc.align {
throw_ub_format!(
"incorrect layout on deallocation: allocation has size {} and alignment {}, but gave size {} and alignment {}",
"incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}",
ptr.alloc_id,
alloc.size.bytes(),
alloc.align.bytes(),
size.bytes(),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir/src/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub struct CopyPropagation;

impl<'tcx> MirPass<'tcx> for CopyPropagation {
fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut Body<'tcx>) {
let opts = &tcx.sess.opts.debugging_opts;
// We only run when the MIR optimization level is > 1.
// This avoids a slow pass, and messing up debug info.
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
// FIXME(76740): This optimization is buggy and can cause unsoundness.
if opts.mir_opt_level <= 1 || !opts.unsound_mir_opts {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/transform/simplify_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
&& bb_l.terminator().kind == bb_r.terminator().kind;
let statement_check = || {
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx, self.tcx.sess.opts.debugging_opts.mir_opt_level);
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx, self.tcx);
if matches!(stmt_equality, StatementEquality::NotEqual) {
// short circuit
None
Expand Down Expand Up @@ -672,7 +672,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
x_bb_idx: BasicBlock,
y: &Statement<'tcx>,
y_bb_idx: BasicBlock,
mir_opt_level: usize,
tcx: TyCtxt<'tcx>,
) -> StatementEquality {
let helper = |rhs: &Rvalue<'tcx>,
place: &Place<'tcx>,
Expand All @@ -693,7 +693,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
Rvalue::Use(operand) if operand.place() == Some(adt_matched_on) => {
// FIXME(76803): This logic is currently broken because it does not take into
// account the current discriminant value.
if mir_opt_level > 2 {
if tcx.sess.opts.debugging_opts.unsound_mir_opts {
StatementEquality::ConsideredEqual(side_to_choose)
} else {
StatementEquality::NotEqual
Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::impl_stable_hash_via_hash;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

use rustc_target::abi::{Align, TargetDataLayout};
use rustc_target::spec::{Target, TargetTriple};

use crate::parse::CrateConfig;
Expand Down Expand Up @@ -748,6 +749,9 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
let min_atomic_width = sess.target.target.min_atomic_width();
let max_atomic_width = sess.target.target.max_atomic_width();
let atomic_cas = sess.target.target.options.atomic_cas;
let layout = TargetDataLayout::parse(&sess.target.target).unwrap_or_else(|err| {
sess.fatal(&err);
});

let mut ret = FxHashSet::default();
ret.reserve(6); // the minimum number of insertions
Expand All @@ -769,18 +773,27 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
if sess.target.target.options.has_elf_tls {
ret.insert((sym::target_thread_local, None));
}
for &i in &[8, 16, 32, 64, 128] {
for &(i, align) in &[
(8, layout.i8_align.abi),
(16, layout.i16_align.abi),
(32, layout.i32_align.abi),
(64, layout.i64_align.abi),
(128, layout.i128_align.abi),
] {
if i >= min_atomic_width && i <= max_atomic_width {
let mut insert_atomic = |s| {
let mut insert_atomic = |s, align: Align| {
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
if atomic_cas {
ret.insert((sym::target_has_atomic, Some(Symbol::intern(s))));
}
if align.bits() == i {
ret.insert((sym::target_has_atomic_equal_alignment, Some(Symbol::intern(s))));
}
};
let s = i.to_string();
insert_atomic(&s);
insert_atomic(&s, align);
if &s == wordsz {
insert_atomic("ptr");
insert_atomic("ptr", layout.pointer_align.abi);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
`hir,typed` (HIR with types for each node),
`hir-tree` (dump the raw HIR),
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
"enable unsound and buggy MIR optimizations (default: no)"),
unstable_options: bool = (false, parse_bool, [UNTRACKED],
"adds unstable command line options to rustc interface (default: no)"),
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ symbols! {
target_feature,
target_feature_11,
target_has_atomic,
target_has_atomic_equal_alignment,
target_has_atomic_load_store,
target_os,
target_pointer_width,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(never_type)]
#![feature(crate_visibility_modifier)]
#![feature(or_patterns)]
#![recursion_limit = "512"] // For rustdoc
Expand Down