Skip to content

Rollup of 6 pull requests #39694

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

Merged
merged 13 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ Lindsey Kuper <[email protected]> <[email protected]>
Luke Metz <[email protected]>
Luqman Aden <[email protected]> <[email protected]>
Luqman Aden <[email protected]> <[email protected]>
Makoto Nakashima <[email protected]> <[email protected]>
Makoto Nakashima <[email protected]> gifnksm <[email protected]>
Makoto Nakashima <[email protected]> NAKASHIMA, Makoto <[email protected]>
NAKASHIMA, Makoto <[email protected]> <[email protected]>
NAKASHIMA, Makoto <[email protected]> <[email protected]>
Marcell Pardavi <[email protected]>
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
Mark Sinclair <[email protected]>
Expand All @@ -150,7 +149,6 @@ Michael Woerister <michaelwoerister@posteo> <michaelwoerister@gmail>
Mickaël Raybaud-Roig <[email protected]> m-r-r <[email protected]>
Ms2ger <[email protected]> <[email protected]>
Mukilan Thiagarajan <[email protected]>
NAKASHIMA, Makoto <[email protected]>
Nathan Wilson <[email protected]>
Nathaniel Herman <[email protected]> Nathaniel Herman <[email protected]>
Neil Pankey <[email protected]> <[email protected]>
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_metadata/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ impl<'tcx> LazySeq<Index> {
}

#[repr(packed)]
#[derive(Copy, Clone)]
#[derive(Copy)]
struct Unaligned<T>(T);

// The derived Clone impl is unsafe for this packed struct since it needs to pass a reference to
// the field to `T::clone`, but this reference may not be properly aligned.
impl<T: Copy> Clone for Unaligned<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Unaligned<T> {
fn get(self) -> T { self.0 }
}
Expand Down
11 changes: 9 additions & 2 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ use syntax::attr;
use syntax::symbol::Symbol;
use syntax_pos::Span;

/// The LLVM module name containing crate-metadata. This includes a `.` on
/// purpose, so it cannot clash with the name of a user-defined module.
pub const METADATA_MODULE_NAME: &'static str = "crate.metadata";
/// The name of the crate-metadata object file the compiler generates. Must
/// match up with `METADATA_MODULE_NAME`.
pub const METADATA_OBJ_NAME: &'static str = "crate.metadata.o";

// RLIB LLVM-BYTECODE OBJECT LAYOUT
// Version 1
// Bytes Data
Expand Down Expand Up @@ -213,7 +220,7 @@ pub fn link_binary(sess: &Session,
remove(sess, &obj);
}
}
remove(sess, &outputs.with_extension("metadata.o"));
remove(sess, &outputs.with_extension(METADATA_OBJ_NAME));
}

out_filenames
Expand Down Expand Up @@ -832,7 +839,7 @@ fn link_args(cmd: &mut Linker,
// object file, so we link that in here.
if crate_type == config::CrateTypeDylib ||
crate_type == config::CrateTypeProcMacro {
cmd.add_object(&outputs.with_extension("metadata.o"));
cmd.add_object(&outputs.with_extension(METADATA_OBJ_NAME));
}

// Try to strip as much out of the generated object by removing unused
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,12 @@ pub fn run_passes(sess: &Session,
// Clean up unwanted temporary files.

// We create the following files by default:
// - crate.#module-name#.bc
// - crate.#module-name#.o
// - crate.metadata.bc
// - crate.metadata.o
// - crate.o (linked from crate.##.o)
// - crate.bc (copied from crate.##.bc)
// - #crate#.#module-name#.bc
// - #crate#.#module-name#.o
// - #crate#.crate.metadata.bc
// - #crate#.crate.metadata.o
// - #crate#.o (linked from crate.##.o)
// - #crate#.bc (copied from crate.##.bc)
// We may create additional files if requested by the user (through
// `-C save-temps` or `--emit=` flags).

Expand Down Expand Up @@ -939,9 +939,9 @@ pub fn run_passes(sess: &Session,
}

// We leave the following files around by default:
// - crate.o
// - crate.metadata.o
// - crate.bc
// - #crate#.o
// - #crate#.crate.metadata.o
// - #crate#.bc
// These are used in linking steps and will be cleaned up afterward.

// FIXME: time_llvm_passes support - does this use a global context or
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
});

let metadata_module = ModuleTranslation {
name: "metadata".to_string(),
name: link::METADATA_MODULE_NAME.to_string(),
symbol_name_hash: 0, // we always rebuild metadata, at least for now
source: ModuleSource::Translated(ModuleLlvm {
llcx: shared_ccx.metadata_llcx(),
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
while span.expn_id != NO_EXPANSION && span.expn_id != COMMAND_LINE_EXPN {
if let Some(callsite_span) = cm.with_expn_info(span.expn_id,
|ei| ei.map(|ei| ei.call_site.clone())) {
// When the current function itself is a result of macro expansion,
// we stop at the function body level because no line stepping can occurr
// at the level above that.
if self.mir.span.expn_id != NO_EXPANSION &&
span.expn_id == self.mir.span.expn_id {
break;
}
span = callsite_span;
} else {
break;
}
}
let scope = self.scope_metadata_for_loc(source_info.scope, span.lo);
// Use span of the outermost call site, while keeping the original lexical scope
// Use span of the outermost expansion site, while keeping the original lexical scope.
(scope, span)
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/debuginfo/macro-stepping.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013-2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn included() {
foo!(); // #inc-loc1

foo2!(); // #inc-loc2

zzz(); // #inc-loc3
}
26 changes: 26 additions & 0 deletions src/test/debuginfo/macro-stepping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ extern crate macro_stepping; // exports new_scope!()
// gdb-command:frame
// gdb-check:[...]#loc6[...]

// gdb-command:continue
// gdb-command:step
// gdb-command:frame
// gdb-check:[...]#inc-loc1[...]
// gdb-command:next
// gdb-command:frame
// gdb-check:[...]#inc-loc2[...]
// gdb-command:next
// gdb-command:frame
// gdb-check:[...]#inc-loc3[...]

// === LLDB TESTS ==================================================================================

// lldb-command:set set stop-line-count-before 0
Expand All @@ -68,6 +79,17 @@ extern crate macro_stepping; // exports new_scope!()
// lldb-command:frame select
// lldb-check:[...]#loc5[...]

// lldb-command:continue
// lldb-command:step
// lldb-command:frame select
// lldb-check:[...]#inc-loc1[...]
// lldb-command:next
// lldb-command:frame select
// lldb-check:[...]#inc-loc2[...]
// lldb-command:next
// lldb-command:frame select
// lldb-check:[...]#inc-loc3[...]

macro_rules! foo {
() => {
let a = 1;
Expand Down Expand Up @@ -99,6 +121,10 @@ fn main() {
"world");

zzz(); // #loc6

included(); // #break
}

fn zzz() {()}

include!("macro-stepping.inc");
61 changes: 46 additions & 15 deletions src/test/run-pass/mir_adt_construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::fmt;

#[repr(C)]
enum CEnum {
Hello = 30,
World = 60
}

fn test1(c: CEnum) -> i32 {
let c2 = CEnum::Hello;
match (c, c2) {
(CEnum::Hello, CEnum::Hello) => 42,
(CEnum::World, CEnum::Hello) => 0,
_ => 1
}
let c2 = CEnum::Hello;
match (c, c2) {
(CEnum::Hello, CEnum::Hello) => 42,
(CEnum::World, CEnum::Hello) => 0,
_ => 1
}
}

#[repr(packed)]
#[derive(PartialEq, Debug)]
struct Pakd {
a: u64,
b: u32,
Expand All @@ -33,6 +34,36 @@ struct Pakd {
e: ()
}

// It is unsafe to use #[derive(Debug)] on a packed struct because the code generated by the derive
// macro takes references to the fields instead of accessing them directly.
impl fmt::Debug for Pakd {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// It's important that we load the fields into locals by-value here. This will do safe
// unaligned loads into the locals, then pass references to the properly-aligned locals to
// the formatting code.
let Pakd { a, b, c, d, e } = *self;
f.debug_struct("Pakd")
.field("a", &a)
.field("b", &b)
.field("c", &c)
.field("d", &d)
.field("e", &e)
.finish()
}
}

// It is unsafe to use #[derive(PartialEq)] on a packed struct because the code generated by the
// derive macro takes references to the fields instead of accessing them directly.
impl PartialEq for Pakd {
fn eq(&self, other: &Pakd) -> bool {
self.a == other.a &&
self.b == other.b &&
self.c == other.c &&
self.d == other.d &&
self.e == other.e
}
}

impl Drop for Pakd {
fn drop(&mut self) {}
}
Expand All @@ -59,12 +90,12 @@ fn test5(x: fn(u32) -> Option<u32>) -> (Option<u32>, Option<u32>) {
}

fn main() {
assert_eq!(test1(CEnum::Hello), 42);
assert_eq!(test1(CEnum::World), 0);
assert_eq!(test2(), Pakd { a: 42, b: 42, c: 42, d: 42, e: () });
assert_eq!(test3(), TupleLike(42, 42));
let t4 = test4(TupleLike);
assert_eq!(t4.0, t4.1);
let t5 = test5(Some);
assert_eq!(t5.0, t5.1);
assert_eq!(test1(CEnum::Hello), 42);
assert_eq!(test1(CEnum::World), 0);
assert_eq!(test2(), Pakd { a: 42, b: 42, c: 42, d: 42, e: () });
assert_eq!(test3(), TupleLike(42, 42));
let t4 = test4(TupleLike);
assert_eq!(t4.0, t4.1);
let t5 = test5(Some);
assert_eq!(t5.0, t5.1);
}
3 changes: 0 additions & 3 deletions src/test/run-pass/u128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-stage0
// ignore-stage1

// ignore-emscripten

#![feature(i128_type, test)]
Expand Down