summaryrefslogtreecommitdiff
path: root/samples/test/gcc5_codegen_bug.rs
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-03-03 13:32:48 +0800
committerJohn Hodge <tpg@mutabah.net>2018-03-03 21:46:56 +0800
commit31a104f0be799974bb8143fff8228797eb3089be (patch)
treea186411020ac985a0729717b7f1c81f6f53b2ee9 /samples/test/gcc5_codegen_bug.rs
parent5c1cc3810b0256f295ef7e838b1874731ec0e1e0 (diff)
downloadmrust-31a104f0be799974bb8143fff8228797eb3089be.tar.gz
Tests - Reduction of the GCC5 bug
Diffstat (limited to 'samples/test/gcc5_codegen_bug.rs')
-rw-r--r--samples/test/gcc5_codegen_bug.rs41
1 files changed, 11 insertions, 30 deletions
diff --git a/samples/test/gcc5_codegen_bug.rs b/samples/test/gcc5_codegen_bug.rs
index 9dab5a82..fde709b6 100644
--- a/samples/test/gcc5_codegen_bug.rs
+++ b/samples/test/gcc5_codegen_bug.rs
@@ -1,43 +1,24 @@
// compile-flags: -O
+// A reduction of issue #63, where gcc5 (but not 6) will generate invalid code for the following iterator adapter's
+// `next` function (seen in librustc)
// ::"core"::iter::Map<::"core"::iter::Chain<::"core"::iter::sources::Once<::"syntax"::ast::NodeId/*S*/,>/*S*/,::"core"::iter::Map<::"core"::slice::Iter<::"syntax"::codemap::Spanned<::"syntax"::ast::PathListItem_/*S*/,>/*S*/,>/*S*/,::"rustc"::closure_I_82<::"rustc"::hir::lowering::LoweringContext/*S*/,>/*S*/,>/*S*/,>/*S*/,::"rustc"::closure_I_83<::"rustc"::hir::lowering::LoweringContext/*S*/,>/*S*/,>
-
-#[derive(Copy,Debug)]
-struct NodeId(u32);
-struct Ident(u32);
-struct PathListItem_
-{
- i: Ident,
- i2: Option<Ident>,
- n: NodeId,
-}
-struct Span(u32, u32, u32);
-struct Spanned<T>
-{
- v: T,
- sp: Span,
-}
-#[derive(Copy,Debug)]
-struct ItemId {
- id: NodeId,
-}
+//
+//
fn main()
{
- // return iter::once(i.id).chain(imports.iter().map(|import| import.node.id)).map(|id| hir::ItemId { id: id }).collect();
- //let list = [ Spanned { v: PathListItem_ { i: Ident(0), i2: None, n: NodeId(0) }, sp: Span(1,1,1) } ];
- let list: [Spanned<PathListItem_>; 0] = [ ];
-
+ // The function call is kinda needed to trigger the bug
+ // - Probably because of how it sets up `rbx` to be non-zero
println!("{:?}", foo(0, &[]));
- println!("{:?}", foo(0, &[ Spanned { v: PathListItem_ { i: Ident(0), i2: None, n: NodeId(0) }, sp: Span(1,1,1) } ]));
- println!("{:?}", foo(0, &vec![]));
}
-fn foo(n: u32, list: &[Spanned<PathListItem_>]) -> Vec<ItemId> {
+// Has to have the second map - even if it's just identity
+fn foo(n: u32, list: &[u32]) -> Vec<u32> {
Iterator::chain(
- ::std::iter::once(NodeId(0)),
- list.iter().map(|v| v.v.n)
- ).map(|id| ItemId { id: id })
+ ::std::iter::once(0u32),
+ list.iter().map(|v| *v)
+ ).map(|id| id)
.collect()
}