Add regression test for debuginfo + LTO · rust-lang/rust@deeba34 (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
1 +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 +// file at the top-level directory of this distribution and at
3 +// http://rust-lang.org/COPYRIGHT.
4 +//
5 +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 +// option. This file may not be copied, modified, or distributed
9 +// except according to those terms.
10 +
11 +// compile-flags: -g --crate-type=rlib
12 +
13 +pub struct StructWithLifetime<'a>(&'a i32);
14 +pub fn mk_struct_with_lt<'a>(x: &'a i32) -> StructWithLifetime<'a> {
15 +StructWithLifetime(x)
16 +}
17 +
18 +pub struct RegularStruct(u32);
19 +pub fn mk_regular_struct(x: u32) -> RegularStruct {
20 +RegularStruct(x)
21 +}
22 +
23 +pub fn take_fn(f: fn(i32) -> i32, x: i32) -> i32 {
24 +f(x)
25 +}
26 +
27 +pub fn with_closure(x: i32) -> i32 {
28 +let closure = |i
29 +
30 +closure(1) + closure(2)
31 +}
32 +
33 +pub fn generic_fn<T>(x: T) -> (T, u32) {
34 +(x, 1)
35 +}
36 +
37 +pub fn user_of_generic_fn(x: f32) -> (f32, u32) {
38 +generic_fn(x)
39 +}
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
8 8 // option. This file may not be copied, modified, or distributed
9 9 // except according to those terms.
10 10
11 -// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib
11 +// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib -g
12 12
13 13 pub mod a {
14 14 pub fn one() -> usize {
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1 +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 +// file at the top-level directory of this distribution and at
3 +// http://rust-lang.org/COPYRIGHT.
4 +//
5 +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 +// option. This file may not be copied, modified, or distributed
9 +// except according to those terms.
10 +
11 +// This test case makes sure that we don't run into LLVM's dreaded
12 +// "possible ODR violation" assertion when compiling with LTO + Debuginfo.
13 +// It covers cases that have traditionally been prone to cause this error.
14 +// If new cases emerge, add them to this file.
15 +
16 +// aux-build:debuginfo-lto-aux.rs
17 +// compile-flags: -C lto -g
18 +// no-prefer-dynamic
19 +
20 +extern crate debuginfo_lto_aux;
21 +
22 +fn some_fn(x: i32) -> i32 {
23 + x + 1
24 +}
25 +
26 +fn main() {
27 +let i = 0;
28 +let _ = debuginfo_lto_aux::mk_struct_with_lt(&i);
29 +let _ = debuginfo_lto_aux::mk_regular_struct(1);
30 +let _ = debuginfo_lto_aux::take_fn(some_fn, 1);
31 +let _ = debuginfo_lto_aux::with_closure(22);
32 +let _ = debuginfo_lto_aux::generic_fn(0f32);
33 +}
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
12 12 // separately compiled.
13 13
14 14 // aux-build:sepcomp_lib.rs
15 -// compile-flags: -C lto
15 +// compile-flags: -C lto -g
16 16 // no-prefer-dynamic
17 17 // ignore-android FIXME #18800
18 18