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 #67414

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d419a5f
Fix pointing at arg when cause is outside of call
VirrageS Dec 1, 2019
e305bf8
Rename tests and add short test description
VirrageS Dec 3, 2019
3594d8b
make htons const fn
tesuji Dec 15, 2019
6ad0b55
Remove now-redundant range check on u128 -> f32 casts
Dec 15, 2019
720b865
[mir-opt] Fix `Inline` pass to handle inlining into `box` expressions
wesleywiser Dec 15, 2019
b50cee3
Move the rest of the mir-opt inline tests into a folder
wesleywiser Dec 15, 2019
aa0ef5a
Fix handling of wasm import modules and names
alexcrichton Dec 16, 2019
e77a55b
Remove outdated references to @T from comments
Dec 17, 2019
71278cb
Remove some unnecessary `ATTR_*` constants.
nnethercote Oct 28, 2019
5891025
Remove `SO_NOSIGPIPE` dummy variable on platforms that don't use it.
reitermarkus Dec 18, 2019
9ce7f80
Allow -Cllvm-args to override rustc's default LLVM args.
michaelwoerister Dec 18, 2019
58352fd
Remove rarely used -Zdisable_instrumentation_preinliner flag.
michaelwoerister Dec 18, 2019
0595fd8
Rollup merge of #67321 - lzutao:htons, r=dtolnay
Mark-Simulacrum Dec 19, 2019
c4fba08
Rollup merge of #67328 - rkruppe:simplify-u128-f32-cast, r=matthewjasper
Mark-Simulacrum Dec 19, 2019
ddd256b
Rollup merge of #67333 - wesleywiser:fix_inline_into_box_place, r=oli…
Mark-Simulacrum Dec 19, 2019
a12ec2e
Rollup merge of #67354 - VirrageS:blame-wrong-line, r=estebank
Mark-Simulacrum Dec 19, 2019
74b1902
Rollup merge of #67363 - alexcrichton:wasm-import-modules, r=eddyb
Mark-Simulacrum Dec 19, 2019
850bd7b
Rollup merge of #67382 - nnethercote:rm-unnecessary-ATTR-constants, r…
Mark-Simulacrum Dec 19, 2019
821dcb9
Rollup merge of #67389 - reitermarkus:dummy-variable, r=shepmaster
Mark-Simulacrum Dec 19, 2019
2d71753
Rollup merge of #67393 - michaelwoerister:llvm-args-override, r=varkor
Mark-Simulacrum Dec 19, 2019
744cd06
Rollup merge of #67394 - matthew-healy:update-libsyntax-ptr-docs, r=D…
Mark-Simulacrum Dec 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@ mod impls_hir;
mod impls_ty;
mod impls_syntax;

pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;

pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
sym::cfg,
ATTR_IF_THIS_CHANGED,
ATTR_THEN_THIS_WOULD_NEED,
ATTR_DIRTY,
ATTR_CLEAN,
ATTR_PARTITION_REUSED,
ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE,
sym::rustc_if_this_changed,
sym::rustc_then_this_would_need,
sym::rustc_dirty,
sym::rustc_clean,
sym::rustc_partition_reused,
sym::rustc_partition_codegened,
sym::rustc_expected_cgu_reuse,
];
11 changes: 11 additions & 0 deletions src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ pub fn from_fn_attrs(
const_cstr!("wasm-import-module"),
&module,
);

let name = codegen_fn_attrs.link_name.unwrap_or_else(|| {
cx.tcx.item_name(instance.def_id())
});
let name = CString::new(&name.as_str()[..]).unwrap();
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("wasm-import-name"),
&name,
);
}
}
}
Expand Down
48 changes: 33 additions & 15 deletions src/librustc_codegen_llvm/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::llvm;
use syntax_pos::symbol::Symbol;
use rustc::session::Session;
use rustc::session::config::PrintRequest;
use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use libc::c_int;
use std::ffi::CString;
Expand Down Expand Up @@ -51,43 +52,60 @@ unsafe fn configure_llvm(sess: &Session) {

llvm::LLVMRustInstallFatalErrorHandler();

fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
full_arg.trim().split(|c: char| {
c == '=' || c.is_whitespace()
}).next().unwrap_or("")
}

let user_specified_args: FxHashSet<_> = sess
.opts
.cg
.llvm_args
.iter()
.map(|s| llvm_arg_to_arg_name(s))
.filter(|s| s.len() > 0)
.collect();

{
let mut add = |arg: &str| {
let s = CString::new(arg).unwrap();
llvm_args.push(s.as_ptr());
llvm_c_strs.push(s);
// This adds the given argument to LLVM. Unless `force` is true
// user specified arguments are *not* overridden.
let mut add = |arg: &str, force: bool| {
if force || !user_specified_args.contains(llvm_arg_to_arg_name(arg)) {
let s = CString::new(arg).unwrap();
llvm_args.push(s.as_ptr());
llvm_c_strs.push(s);
}
};
add("rustc"); // fake program name
if sess.time_llvm_passes() { add("-time-passes"); }
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
if sess.opts.debugging_opts.disable_instrumentation_preinliner {
add("-disable-preinline");
}
add("rustc", true); // fake program name
if sess.time_llvm_passes() { add("-time-passes", false); }
if sess.print_llvm_passes() { add("-debug-pass=Structure", false); }

if sess.opts.debugging_opts.generate_arange_section {
add("-generate-arange-section");
add("-generate-arange-section", false);
}
if get_major_version() >= 8 {
match sess.opts.debugging_opts.merge_functions
.unwrap_or(sess.target.target.options.merge_functions) {
MergeFunctions::Disabled |
MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
add("-mergefunc-use-aliases");
add("-mergefunc-use-aliases", false);
}
}
}

if sess.target.target.target_os == "emscripten" &&
sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions");
add("-enable-emscripten-cxx-exceptions", false);
}

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

for arg in &sess.opts.cg.llvm_args {
add(&(*arg));
add(&(*arg), true);
}
}

Expand Down
43 changes: 7 additions & 36 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
llval
}
}
(CastTy::Int(_), CastTy::Float) => {
if signed {
bx.sitofp(llval, ll_t_out)
} else {
bx.uitofp(llval, ll_t_out)
}
}
(CastTy::Ptr(_), CastTy::Ptr(_)) |
(CastTy::FnPtr, CastTy::Ptr(_)) |
(CastTy::RPtr(_), CastTy::Ptr(_)) =>
Expand All @@ -352,8 +359,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed);
bx.inttoptr(usize_llval, ll_t_out)
}
(CastTy::Int(_), CastTy::Float) =>
cast_int_to_float(&mut bx, signed, llval, ll_t_in, ll_t_out),
(CastTy::Float, CastTy::Int(IntTy::I)) =>
cast_float_to_int(&mut bx, true, llval, ll_t_in, ll_t_out),
(CastTy::Float, CastTy::Int(_)) =>
Expand Down Expand Up @@ -720,40 +725,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}

fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
signed: bool,
x: Bx::Value,
int_ty: Bx::Type,
float_ty: Bx::Type
) -> Bx::Value {
// Most integer types, even i128, fit into [-f32::MAX, f32::MAX] after rounding.
// It's only u128 -> f32 that can cause overflows (i.e., should yield infinity).
// LLVM's uitofp produces undef in those cases, so we manually check for that case.
let is_u128_to_f32 = !signed &&
bx.cx().int_width(int_ty) == 128 &&
bx.cx().float_width(float_ty) == 32;
if is_u128_to_f32 {
// All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity,
// and for everything else LLVM's uitofp works just fine.
use rustc_apfloat::ieee::Single;
const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1)
<< (Single::MAX_EXP - Single::PRECISION as i16);
let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP);
let overflow = bx.icmp(IntPredicate::IntUGE, x, max);
let infinity_bits = bx.cx().const_u32(ieee::Single::INFINITY.to_bits() as u32);
let infinity = bx.bitcast(infinity_bits, float_ty);
let fp = bx.uitofp(x, float_ty);
bx.select(overflow, infinity, fp)
} else {
if signed {
bx.sitofp(x, float_ty)
} else {
bx.uitofp(x, float_ty)
}
}
}

fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
signed: bool,
Expand Down
28 changes: 24 additions & 4 deletions src/librustc_codegen_utils/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,32 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Symbol {
};

let attrs = tcx.codegen_fn_attrs(def_id);

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

if let Some(name) = attrs.export_name {
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ use rustc_data_structures::graph::implementation::{
};
use rustc::hir;
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
use std::env;
use std::fs::{self, File};
use std::io::Write;
use syntax::ast;
use syntax::{ast, symbol::sym};
use syntax_pos::Span;

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

// Check paths.
Expand Down Expand Up @@ -114,7 +113,7 @@ impl IfThisChanged<'tcx> {
let def_id = self.tcx.hir().local_def_id(hir_id);
let def_path_hash = self.tcx.def_path_hash(def_id);
for attr in attrs {
if attr.check_name(ATTR_IF_THIS_CHANGED) {
if attr.check_name(sym::rustc_if_this_changed) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
None => def_path_hash.to_dep_node(DepKind::Hir),
Expand All @@ -130,7 +129,7 @@ impl IfThisChanged<'tcx> {
}
};
self.if_this_changed.push((attr.span, def_id, dep_node));
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
} else if attr.check_name(sym::rustc_then_this_would_need) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
Some(n) => {
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_incremental/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use rustc::ty::TyCtxt;
use std::collections::BTreeSet;
use syntax::ast;
use syntax::symbol::{Symbol, sym};
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE};

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

impl AssertModuleSource<'tcx> {
fn check_attr(&self, attr: &ast::Attribute) {
let (expected_reuse, comp_kind) = if attr.check_name(ATTR_PARTITION_REUSED) {
let (expected_reuse, comp_kind) = if attr.check_name(sym::rustc_partition_reused) {
(CguReuse::PreLto, ComparisonKind::AtLeast)
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
} else if attr.check_name(sym::rustc_partition_codegened) {
(CguReuse::No, ComparisonKind::Exact)
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
} else if attr.check_name(sym::rustc_expected_cgu_reuse) {
match &*self.field(attr, sym::kind).as_str() {
"no" => (CguReuse::No, ComparisonKind::Exact),
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rustc::hir::Node as HirNode;
use rustc::hir::def_id::DefId;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::intravisit;
use rustc::ich::{ATTR_DIRTY, ATTR_CLEAN};
use rustc::ty::TyCtxt;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -224,7 +223,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {

let mut all_attrs = FindAllAttrs {
tcx,
attr_names: vec![ATTR_DIRTY, ATTR_CLEAN],
attr_names: vec![sym::rustc_dirty, sym::rustc_clean],
found_attrs: vec![],
};
intravisit::walk_crate(&mut all_attrs, krate);
Expand All @@ -246,9 +245,9 @@ impl DirtyCleanVisitor<'tcx> {
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute)
-> Option<Assertion>
{
let is_clean = if attr.check_name(ATTR_DIRTY) {
let is_clean = if attr.check_name(sym::rustc_dirty) {
false
} else if attr.check_name(ATTR_CLEAN) {
} else if attr.check_name(sym::rustc_clean) {
true
} else {
// skip: not rustc_clean/dirty
Expand Down
30 changes: 20 additions & 10 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {

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

Expand Down Expand Up @@ -695,14 +695,24 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
fn visit_place(
&mut self,
place: &mut Place<'tcx>,
context: PlaceContext,
location: Location,
_context: PlaceContext,
_location: Location,
) {
if let Some(RETURN_PLACE) = place.as_local() {
// Return pointer; update the place itself
*place = self.destination.clone();
} else {
self.super_place(place, context, location);
match &mut place.base {
PlaceBase::Static(_) => {},
PlaceBase::Local(l) => {
// If this is the `RETURN_PLACE`, we need to rebase any projections onto it.
let dest_proj_len = self.destination.projection.len();
if *l == RETURN_PLACE && dest_proj_len > 0 {
let mut projs = Vec::with_capacity(dest_proj_len + place.projection.len());
projs.extend(self.destination.projection);
projs.extend(place.projection);

place.projection = self.tcx.intern_place_elems(&*projs);
}

*l = self.make_integrate_local(l);
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"extra arguments to prepend to the linker invocation (space separated)"),
profile: bool = (false, parse_bool, [TRACKED],
"insert profiling code"),
disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED],
"Disable the instrumentation pre-inliner, useful for profiling / PGO."),
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
"choose which RELRO level to use"),
nll_facts: bool = (false, parse_bool, [UNTRACKED],
Expand Down
Loading