From ddb0a7855c335ec7a7c1d1f5a2eef45a0ce6c835 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 7 Feb 2017 01:55:17 +0100 Subject: [PATCH 1/7] Unignore u128 test for stage 0,1 Even more SNAP cleanup. --- src/test/run-pass/u128.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/run-pass/u128.rs b/src/test/run-pass/u128.rs index 139d42e3a3524..ac3dfcdfde155 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)] From e5396e025ed886c827348aac996c4c6c846fb5ab Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 7 Feb 2017 12:24:43 -0500 Subject: [PATCH 2/7] Choose different name for metadata obj-file to avoid clashes with user-chosen names. --- src/librustc_trans/back/link.rs | 11 +++++++++-- src/librustc_trans/back/write.rs | 18 +++++++++--------- src/librustc_trans/base.rs | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 4ddf8a883bc48..6bdb3ce631fb1 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 b3a2d66a07c11..fa43d94e9c114 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -866,12 +866,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). @@ -919,9 +919,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 9bd19d5bbb3e4..a4841a914deda 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1146,7 +1146,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(), From 0dbdb2d0d08818ffe61ab0c1024356957ba0a543 Mon Sep 17 00:00:00 2001 From: Jan Zerebecki Date: Thu, 9 Feb 2017 01:45:58 +0100 Subject: [PATCH 3/7] Fix mailmap for @gifnksm cc rust-lang-nursery/thanks#71 --- .mailmap | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.mailmap b/.mailmap index 1ae0aae2d01ba..4b4f343d15a9d 100644 --- a/.mailmap +++ b/.mailmap @@ -132,9 +132,8 @@ Lindsey Kuper Luke Metz Luqman Aden Luqman Aden -Makoto Nakashima -Makoto Nakashima gifnksm -Makoto Nakashima NAKASHIMA, Makoto +NAKASHIMA, Makoto +NAKASHIMA, Makoto Marcell Pardavi Margaret Meyerhofer Mark Sinclair @@ -150,7 +149,6 @@ Michael Woerister Mickaƫl Raybaud-Roig m-r-r Ms2ger Mukilan Thiagarajan -NAKASHIMA, Makoto Nathan Wilson Nathaniel Herman Nathaniel Herman Neil Pankey From d113b39fbf089621c3985af9d50a888cd02dd432 Mon Sep 17 00:00:00 2001 From: Vadim Chugunov Date: Wed, 8 Feb 2017 22:09:51 -0800 Subject: [PATCH 4/7] Exclude top-level macro expansions from source location override. --- src/librustc_trans/mir/mod.rs | 9 ++++++++- src/test/debuginfo/macro-stepping.inc | 17 +++++++++++++++++ src/test/debuginfo/macro-stepping.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/test/debuginfo/macro-stepping.inc diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index 8a0a97a563439..949e1dd92a6d6 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 0000000000000..6aaf7ed421e7f --- /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 or the MIT license +// , 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 37355ed377b79..ca2c1e0c8f029 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"); From b8b898093cf2b37dfe5c192cbd7f1004073fde0e Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 9 Feb 2017 03:09:36 -0800 Subject: [PATCH 5/7] Avoid unsafe unaligned loads in test. --- src/test/run-pass/mir_adt_construction.rs | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/run-pass/mir_adt_construction.rs b/src/test/run-pass/mir_adt_construction.rs index 6b47721ab4b32..c54cbe7bd6f45 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, @@ -24,7 +26,6 @@ fn test1(c: CEnum) -> i32 { } #[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) {} } From 2589f4a7511ab04a3325b0372cd2ae174940c6c8 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 9 Feb 2017 03:10:33 -0800 Subject: [PATCH 6/7] Fix indentation in test. --- src/test/run-pass/mir_adt_construction.rs | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/run-pass/mir_adt_construction.rs b/src/test/run-pass/mir_adt_construction.rs index c54cbe7bd6f45..eb96d94efec93 100644 --- a/src/test/run-pass/mir_adt_construction.rs +++ b/src/test/run-pass/mir_adt_construction.rs @@ -17,12 +17,12 @@ 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)] @@ -90,12 +90,12 @@ fn test5(x: fn(u32) -> Option) -> (Option, Option) { } 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); } From 5eaa7c2d7df58f186015a40778ea888428d008e8 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 9 Feb 2017 03:38:52 -0800 Subject: [PATCH 7/7] Fix unaligned load in librustc_metadata::index. --- src/librustc_metadata/index.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_metadata/index.rs b/src/librustc_metadata/index.rs index 5b52b268849d3..db9fc870fa86a 100644 --- a/src/librustc_metadata/index.rs +++ b/src/librustc_metadata/index.rs @@ -96,9 +96,17 @@ impl<'tcx> LazySeq { } #[repr(packed)] -#[derive(Copy, Clone)] +#[derive(Copy)] struct Unaligned(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 Clone for Unaligned { + fn clone(&self) -> Self { + *self + } +} + impl Unaligned { fn get(self) -> T { self.0 } }