about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-02-09 21:58:10 +0000
committerbors <bors@rust-lang.org>2017-02-09 21:58:10 +0000
commit24a70eb598a76edb0941f628a87946b40f2a1c83 (patch)
treef31e4a69825ceab919636f3f86537bf563f60f86 /src
parent405327635419e22a956dfe8f7caf4817c8ae5e93 (diff)
parent55c17a599432aef3b725663a482c853f0263e183 (diff)
downloadrust-24a70eb598a76edb0941f628a87946b40f2a1c83.tar.gz
rust-24a70eb598a76edb0941f628a87946b40f2a1c83.zip
Auto merge of #39694 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #39604, #39619, #39670, #39678, #39682, #39683
- Failed merges:
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/index.rs10
-rw-r--r--src/librustc_trans/back/link.rs11
-rw-r--r--src/librustc_trans/back/write.rs18
-rw-r--r--src/librustc_trans/base.rs2
-rw-r--r--src/librustc_trans/mir/mod.rs9
-rw-r--r--src/test/debuginfo/macro-stepping.inc17
-rw-r--r--src/test/debuginfo/macro-stepping.rs26
-rw-r--r--src/test/run-pass/mir_adt_construction.rs61
-rw-r--r--src/test/run-pass/u128.rs3
9 files changed, 125 insertions, 32 deletions
diff --git a/src/librustc_metadata/index.rs b/src/librustc_metadata/index.rs
index 5b52b268849..db9fc870fa8 100644
--- a/src/librustc_metadata/index.rs
+++ b/src/librustc_metadata/index.rs
@@ -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 }
 }
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index 1cbfa26b705..9d48dc523d3 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -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
@@ -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
@@ -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
diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs
index 5c4a5a9a442..b717254ef0d 100644
--- a/src/librustc_trans/back/write.rs
+++ b/src/librustc_trans/back/write.rs
@@ -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).
 
@@ -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
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 5312cc60b09..ce02c9725d1 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -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(),
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index e017c8f2532..0cfc2c8d163 100644
--- a/src/librustc_trans/mir/mod.rs
+++ b/src/librustc_trans/mir/mod.rs
@@ -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)
         }
     }
diff --git a/src/test/debuginfo/macro-stepping.inc b/src/test/debuginfo/macro-stepping.inc
new file mode 100644
index 00000000000..6aaf7ed421e
--- /dev/null
+++ b/src/test/debuginfo/macro-stepping.inc
@@ -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
+}
diff --git a/src/test/debuginfo/macro-stepping.rs b/src/test/debuginfo/macro-stepping.rs
index 37355ed377b..ca2c1e0c8f0 100644
--- a/src/test/debuginfo/macro-stepping.rs
+++ b/src/test/debuginfo/macro-stepping.rs
@@ -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
@@ -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;
@@ -99,6 +121,10 @@ fn main() {
              "world");
 
     zzz(); // #loc6
+
+    included(); // #break
 }
 
 fn zzz() {()}
+
+include!("macro-stepping.inc");
diff --git a/src/test/run-pass/mir_adt_construction.rs b/src/test/run-pass/mir_adt_construction.rs
index 6b47721ab4b..eb96d94efec 100644
--- a/src/test/run-pass/mir_adt_construction.rs
+++ b/src/test/run-pass/mir_adt_construction.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::fmt;
+
 #[repr(C)]
 enum CEnum {
     Hello = 30,
@@ -15,16 +17,15 @@ enum CEnum {
 }
 
 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,
@@ -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) {}
 }
@@ -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);
 }
diff --git a/src/test/run-pass/u128.rs b/src/test/run-pass/u128.rs
index 139d42e3a35..ac3dfcdfde1 100644
--- a/src/test/run-pass/u128.rs
+++ b/src/test/run-pass/u128.rs
@@ -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)]