Skip to content

Commit 246bf36

Browse files
committed
Auto merge of #67414 - Mark-Simulacrum:rollup-gxjwn6c, r=Mark-Simulacrum
Rollup of 9 pull requests Successful merges: - #67321 (make htons const fn) - #67328 (Remove now-redundant range check on u128 -> f32 casts) - #67333 ([mir-opt] Fix `Inline` pass to handle inlining into `box` expressions) - #67354 (Fix pointing at arg when cause is outside of call) - #67363 (Fix handling of wasm import modules and names) - #67382 (Remove some unnecessary `ATTR_*` constants.) - #67389 (Remove `SO_NOSIGPIPE` dummy variable on platforms that don't use it.) - #67393 (Enable opting out of specific default LLVM arguments.) - #67394 (Remove outdated references to @t from comments) Failed merges: r? @ghost
2 parents c605199 + 744cd06 commit 246bf36

34 files changed

+441
-170
lines changed

src/librustc/ich/mod.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ mod impls_hir;
1212
mod impls_ty;
1313
mod impls_syntax;
1414

15-
pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
16-
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
17-
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
18-
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
19-
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
20-
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
21-
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;
22-
2315
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
2416
sym::cfg,
25-
ATTR_IF_THIS_CHANGED,
26-
ATTR_THEN_THIS_WOULD_NEED,
27-
ATTR_DIRTY,
28-
ATTR_CLEAN,
29-
ATTR_PARTITION_REUSED,
30-
ATTR_PARTITION_CODEGENED,
31-
ATTR_EXPECTED_CGU_REUSE,
17+
sym::rustc_if_this_changed,
18+
sym::rustc_then_this_would_need,
19+
sym::rustc_dirty,
20+
sym::rustc_clean,
21+
sym::rustc_partition_reused,
22+
sym::rustc_partition_codegened,
23+
sym::rustc_expected_cgu_reuse,
3224
];

src/librustc_codegen_llvm/attributes.rs

+11
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ pub fn from_fn_attrs(
344344
const_cstr!("wasm-import-module"),
345345
&module,
346346
);
347+
348+
let name = codegen_fn_attrs.link_name.unwrap_or_else(|| {
349+
cx.tcx.item_name(instance.def_id())
350+
});
351+
let name = CString::new(&name.as_str()[..]).unwrap();
352+
llvm::AddFunctionAttrStringValue(
353+
llfn,
354+
llvm::AttributePlace::Function,
355+
const_cstr!("wasm-import-name"),
356+
&name,
357+
);
347358
}
348359
}
349360
}

src/librustc_codegen_llvm/llvm_util.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::llvm;
33
use syntax_pos::symbol::Symbol;
44
use rustc::session::Session;
55
use rustc::session::config::PrintRequest;
6+
use rustc_data_structures::fx::FxHashSet;
67
use rustc_target::spec::{MergeFunctions, PanicStrategy};
78
use libc::c_int;
89
use std::ffi::CString;
@@ -51,43 +52,60 @@ unsafe fn configure_llvm(sess: &Session) {
5152

5253
llvm::LLVMRustInstallFatalErrorHandler();
5354

55+
fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
56+
full_arg.trim().split(|c: char| {
57+
c == '=' || c.is_whitespace()
58+
}).next().unwrap_or("")
59+
}
60+
61+
let user_specified_args: FxHashSet<_> = sess
62+
.opts
63+
.cg
64+
.llvm_args
65+
.iter()
66+
.map(|s| llvm_arg_to_arg_name(s))
67+
.filter(|s| s.len() > 0)
68+
.collect();
69+
5470
{
55-
let mut add = |arg: &str| {
56-
let s = CString::new(arg).unwrap();
57-
llvm_args.push(s.as_ptr());
58-
llvm_c_strs.push(s);
71+
// This adds the given argument to LLVM. Unless `force` is true
72+
// user specified arguments are *not* overridden.
73+
let mut add = |arg: &str, force: bool| {
74+
if force || !user_specified_args.contains(llvm_arg_to_arg_name(arg)) {
75+
let s = CString::new(arg).unwrap();
76+
llvm_args.push(s.as_ptr());
77+
llvm_c_strs.push(s);
78+
}
5979
};
60-
add("rustc"); // fake program name
61-
if sess.time_llvm_passes() { add("-time-passes"); }
62-
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
63-
if sess.opts.debugging_opts.disable_instrumentation_preinliner {
64-
add("-disable-preinline");
65-
}
80+
add("rustc", true); // fake program name
81+
if sess.time_llvm_passes() { add("-time-passes", false); }
82+
if sess.print_llvm_passes() { add("-debug-pass=Structure", false); }
83+
6684
if sess.opts.debugging_opts.generate_arange_section {
67-
add("-generate-arange-section");
85+
add("-generate-arange-section", false);
6886
}
6987
if get_major_version() >= 8 {
7088
match sess.opts.debugging_opts.merge_functions
7189
.unwrap_or(sess.target.target.options.merge_functions) {
7290
MergeFunctions::Disabled |
7391
MergeFunctions::Trampolines => {}
7492
MergeFunctions::Aliases => {
75-
add("-mergefunc-use-aliases");
93+
add("-mergefunc-use-aliases", false);
7694
}
7795
}
7896
}
7997

8098
if sess.target.target.target_os == "emscripten" &&
8199
sess.panic_strategy() == PanicStrategy::Unwind {
82-
add("-enable-emscripten-cxx-exceptions");
100+
add("-enable-emscripten-cxx-exceptions", false);
83101
}
84102

85103
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
86104
// during inlining. Unfortunately these may block other optimizations.
87-
add("-preserve-alignment-assumptions-during-inlining=false");
105+
add("-preserve-alignment-assumptions-during-inlining=false", false);
88106

89107
for arg in &sess.opts.cg.llvm_args {
90-
add(&(*arg));
108+
add(&(*arg), true);
91109
}
92110
}
93111

src/librustc_codegen_ssa/mir/rvalue.rs

+7-36
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
341341
llval
342342
}
343343
}
344+
(CastTy::Int(_), CastTy::Float) => {
345+
if signed {
346+
bx.sitofp(llval, ll_t_out)
347+
} else {
348+
bx.uitofp(llval, ll_t_out)
349+
}
350+
}
344351
(CastTy::Ptr(_), CastTy::Ptr(_)) |
345352
(CastTy::FnPtr, CastTy::Ptr(_)) |
346353
(CastTy::RPtr(_), CastTy::Ptr(_)) =>
@@ -352,8 +359,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
352359
let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed);
353360
bx.inttoptr(usize_llval, ll_t_out)
354361
}
355-
(CastTy::Int(_), CastTy::Float) =>
356-
cast_int_to_float(&mut bx, signed, llval, ll_t_in, ll_t_out),
357362
(CastTy::Float, CastTy::Int(IntTy::I)) =>
358363
cast_float_to_int(&mut bx, true, llval, ll_t_in, ll_t_out),
359364
(CastTy::Float, CastTy::Int(_)) =>
@@ -720,40 +725,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
720725
}
721726
}
722727

723-
fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
724-
bx: &mut Bx,
725-
signed: bool,
726-
x: Bx::Value,
727-
int_ty: Bx::Type,
728-
float_ty: Bx::Type
729-
) -> Bx::Value {
730-
// Most integer types, even i128, fit into [-f32::MAX, f32::MAX] after rounding.
731-
// It's only u128 -> f32 that can cause overflows (i.e., should yield infinity).
732-
// LLVM's uitofp produces undef in those cases, so we manually check for that case.
733-
let is_u128_to_f32 = !signed &&
734-
bx.cx().int_width(int_ty) == 128 &&
735-
bx.cx().float_width(float_ty) == 32;
736-
if is_u128_to_f32 {
737-
// All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity,
738-
// and for everything else LLVM's uitofp works just fine.
739-
use rustc_apfloat::ieee::Single;
740-
const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1)
741-
<< (Single::MAX_EXP - Single::PRECISION as i16);
742-
let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP);
743-
let overflow = bx.icmp(IntPredicate::IntUGE, x, max);
744-
let infinity_bits = bx.cx().const_u32(ieee::Single::INFINITY.to_bits() as u32);
745-
let infinity = bx.bitcast(infinity_bits, float_ty);
746-
let fp = bx.uitofp(x, float_ty);
747-
bx.select(overflow, infinity, fp)
748-
} else {
749-
if signed {
750-
bx.sitofp(x, float_ty)
751-
} else {
752-
bx.uitofp(x, float_ty)
753-
}
754-
}
755-
}
756-
757728
fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
758729
bx: &mut Bx,
759730
signed: bool,

src/librustc_codegen_utils/symbol_names.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,32 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Symbol {
142142
};
143143

144144
let attrs = tcx.codegen_fn_attrs(def_id);
145+
146+
// Foreign items by default use no mangling for their symbol name. There's a
147+
// few exceptions to this rule though:
148+
//
149+
// * This can be overridden with the `#[link_name]` attribute
150+
//
151+
// * On the wasm32 targets there is a bug (or feature) in LLD [1] where the
152+
// same-named symbol when imported from different wasm modules will get
153+
// hooked up incorectly. As a result foreign symbols, on the wasm target,
154+
// with a wasm import module, get mangled. Additionally our codegen will
155+
// deduplicate symbols based purely on the symbol name, but for wasm this
156+
// isn't quite right because the same-named symbol on wasm can come from
157+
// different modules. For these reasons if `#[link(wasm_import_module)]`
158+
// is present we mangle everything on wasm because the demangled form will
159+
// show up in the `wasm-import-name` custom attribute in LLVM IR.
160+
//
161+
// [1]: https://bugs.llvm.org/show_bug.cgi?id=44316
145162
if is_foreign {
146-
if let Some(name) = attrs.link_name {
147-
return name;
163+
if tcx.sess.target.target.arch != "wasm32" ||
164+
!tcx.wasm_import_module_map(def_id.krate).contains_key(&def_id)
165+
{
166+
if let Some(name) = attrs.link_name {
167+
return name;
168+
}
169+
return tcx.item_name(def_id);
148170
}
149-
// Don't mangle foreign items.
150-
return tcx.item_name(def_id);
151171
}
152172

153173
if let Some(name) = attrs.export_name {

src/librustc_incremental/assert_dep_graph.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ use rustc_data_structures::graph::implementation::{
4444
};
4545
use rustc::hir;
4646
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
47-
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
4847
use std::env;
4948
use std::fs::{self, File};
5049
use std::io::Write;
51-
use syntax::ast;
50+
use syntax::{ast, symbol::sym};
5251
use syntax_pos::Span;
5352

5453
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
@@ -78,7 +77,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
7877
assert!(tcx.sess.opts.debugging_opts.query_dep_graph,
7978
"cannot use the `#[{}]` or `#[{}]` annotations \
8079
without supplying `-Z query-dep-graph`",
81-
ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED);
80+
sym::rustc_if_this_changed, sym::rustc_then_this_would_need);
8281
}
8382

8483
// Check paths.
@@ -114,7 +113,7 @@ impl IfThisChanged<'tcx> {
114113
let def_id = self.tcx.hir().local_def_id(hir_id);
115114
let def_path_hash = self.tcx.def_path_hash(def_id);
116115
for attr in attrs {
117-
if attr.check_name(ATTR_IF_THIS_CHANGED) {
116+
if attr.check_name(sym::rustc_if_this_changed) {
118117
let dep_node_interned = self.argument(attr);
119118
let dep_node = match dep_node_interned {
120119
None => def_path_hash.to_dep_node(DepKind::Hir),
@@ -130,7 +129,7 @@ impl IfThisChanged<'tcx> {
130129
}
131130
};
132131
self.if_this_changed.push((attr.span, def_id, dep_node));
133-
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
132+
} else if attr.check_name(sym::rustc_then_this_would_need) {
134133
let dep_node_interned = self.argument(attr);
135134
let dep_node = match dep_node_interned {
136135
Some(n) => {

src/librustc_incremental/assert_module_sources.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use rustc::ty::TyCtxt;
2828
use std::collections::BTreeSet;
2929
use syntax::ast;
3030
use syntax::symbol::{Symbol, sym};
31-
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
32-
ATTR_EXPECTED_CGU_REUSE};
3331

3432
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3533
tcx.dep_graph.with_ignore(|| {
@@ -62,11 +60,11 @@ struct AssertModuleSource<'tcx> {
6260

6361
impl AssertModuleSource<'tcx> {
6462
fn check_attr(&self, attr: &ast::Attribute) {
65-
let (expected_reuse, comp_kind) = if attr.check_name(ATTR_PARTITION_REUSED) {
63+
let (expected_reuse, comp_kind) = if attr.check_name(sym::rustc_partition_reused) {
6664
(CguReuse::PreLto, ComparisonKind::AtLeast)
67-
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
65+
} else if attr.check_name(sym::rustc_partition_codegened) {
6866
(CguReuse::No, ComparisonKind::Exact)
69-
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
67+
} else if attr.check_name(sym::rustc_expected_cgu_reuse) {
7068
match &*self.field(attr, sym::kind).as_str() {
7169
"no" => (CguReuse::No, ComparisonKind::Exact),
7270
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),

src/librustc_incremental/persist/dirty_clean.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc::hir::Node as HirNode;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2424
use rustc::hir::intravisit;
25-
use rustc::ich::{ATTR_DIRTY, ATTR_CLEAN};
2625
use rustc::ty::TyCtxt;
2726
use rustc_data_structures::fingerprint::Fingerprint;
2827
use rustc_data_structures::fx::FxHashSet;
@@ -224,7 +223,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
224223

225224
let mut all_attrs = FindAllAttrs {
226225
tcx,
227-
attr_names: vec![ATTR_DIRTY, ATTR_CLEAN],
226+
attr_names: vec![sym::rustc_dirty, sym::rustc_clean],
228227
found_attrs: vec![],
229228
};
230229
intravisit::walk_crate(&mut all_attrs, krate);
@@ -246,9 +245,9 @@ impl DirtyCleanVisitor<'tcx> {
246245
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute)
247246
-> Option<Assertion>
248247
{
249-
let is_clean = if attr.check_name(ATTR_DIRTY) {
248+
let is_clean = if attr.check_name(sym::rustc_dirty) {
250249
false
251-
} else if attr.check_name(ATTR_CLEAN) {
250+
} else if attr.check_name(sym::rustc_clean) {
252251
true
253252
} else {
254253
// skip: not rustc_clean/dirty

src/librustc_mir/transform/inline.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,9 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {
663663

664664
fn make_integrate_local(&self, local: &Local) -> Local {
665665
if *local == RETURN_PLACE {
666-
match self.destination.as_local() {
667-
Some(l) => return l,
668-
ref place => bug!("Return place is {:?}, not local", place),
666+
match self.destination.base {
667+
PlaceBase::Local(l) => return l,
668+
PlaceBase::Static(ref s) => bug!("Return place is {:?}, not local", s),
669669
}
670670
}
671671

@@ -695,14 +695,24 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
695695
fn visit_place(
696696
&mut self,
697697
place: &mut Place<'tcx>,
698-
context: PlaceContext,
699-
location: Location,
698+
_context: PlaceContext,
699+
_location: Location,
700700
) {
701-
if let Some(RETURN_PLACE) = place.as_local() {
702-
// Return pointer; update the place itself
703-
*place = self.destination.clone();
704-
} else {
705-
self.super_place(place, context, location);
701+
match &mut place.base {
702+
PlaceBase::Static(_) => {},
703+
PlaceBase::Local(l) => {
704+
// If this is the `RETURN_PLACE`, we need to rebase any projections onto it.
705+
let dest_proj_len = self.destination.projection.len();
706+
if *l == RETURN_PLACE && dest_proj_len > 0 {
707+
let mut projs = Vec::with_capacity(dest_proj_len + place.projection.len());
708+
projs.extend(self.destination.projection);
709+
projs.extend(place.projection);
710+
711+
place.projection = self.tcx.intern_place_elems(&*projs);
712+
}
713+
714+
*l = self.make_integrate_local(l);
715+
}
706716
}
707717
}
708718

src/librustc_session/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
14881488
"extra arguments to prepend to the linker invocation (space separated)"),
14891489
profile: bool = (false, parse_bool, [TRACKED],
14901490
"insert profiling code"),
1491-
disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED],
1492-
"Disable the instrumentation pre-inliner, useful for profiling / PGO."),
14931491
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
14941492
"choose which RELRO level to use"),
14951493
nll_facts: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)