Skip to content

Commit deeba34

Browse files
Add regression test for debuginfo + LTO
1 parent a167c04 commit deeba34

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed
Original file line numberDiff line numberDiff 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| { x + 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+
}

src/test/run-pass/auxiliary/sepcomp_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib
11+
// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib -g
1212

1313
pub mod a {
1414
pub fn one() -> usize {

src/test/run-pass/debuginfo-lto.rs

+33
Original file line numberDiff line numberDiff 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+
}

src/test/run-pass/sepcomp-lib-lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// separately compiled.
1313

1414
// aux-build:sepcomp_lib.rs
15-
// compile-flags: -C lto
15+
// compile-flags: -C lto -g
1616
// no-prefer-dynamic
1717
// ignore-android FIXME #18800
1818

0 commit comments

Comments
 (0)