about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo.net>2017-01-18 11:24:43 -0500
committerMichael Woerister <michaelwoerister@posteo.net>2017-01-18 11:24:43 -0500
commitdeeba3443e186628fca98e7b74a0ac0616c5fa2d (patch)
treef1f8424c5fbc2286d0f3258232c462db11f5a2e8 /src/test
parenta167c042abed695a049abf3919ce929765e6cc30 (diff)
downloadrust-deeba3443e186628fca98e7b74a0ac0616c5fa2d.tar.gz
rust-deeba3443e186628fca98e7b74a0ac0616c5fa2d.zip
Add regression test for debuginfo + LTO
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/auxiliary/debuginfo-lto-aux.rs39
-rw-r--r--src/test/run-pass/auxiliary/sepcomp_lib.rs2
-rw-r--r--src/test/run-pass/debuginfo-lto.rs33
-rw-r--r--src/test/run-pass/sepcomp-lib-lto.rs2
4 files changed, 74 insertions, 2 deletions
diff --git a/src/test/run-pass/auxiliary/debuginfo-lto-aux.rs b/src/test/run-pass/auxiliary/debuginfo-lto-aux.rs
new file mode 100644
index 00000000000..88e54d30172
--- /dev/null
+++ b/src/test/run-pass/auxiliary/debuginfo-lto-aux.rs
@@ -0,0 +1,39 @@
+// Copyright 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.
+
+// compile-flags: -g --crate-type=rlib
+
+pub struct StructWithLifetime<'a>(&'a i32);
+pub fn mk_struct_with_lt<'a>(x: &'a i32) -> StructWithLifetime<'a> {
+    StructWithLifetime(x)
+}
+
+pub struct RegularStruct(u32);
+pub fn mk_regular_struct(x: u32) -> RegularStruct {
+    RegularStruct(x)
+}
+
+pub fn take_fn(f: fn(i32) -> i32, x: i32) -> i32 {
+    f(x)
+}
+
+pub fn with_closure(x: i32) -> i32 {
+    let closure = |i| { x + i };
+
+    closure(1) + closure(2)
+}
+
+pub fn generic_fn<T>(x: T) -> (T, u32) {
+    (x, 1)
+}
+
+pub fn user_of_generic_fn(x: f32) -> (f32, u32) {
+    generic_fn(x)
+}
diff --git a/src/test/run-pass/auxiliary/sepcomp_lib.rs b/src/test/run-pass/auxiliary/sepcomp_lib.rs
index 9aa16fb2694..6f48978a000 100644
--- a/src/test/run-pass/auxiliary/sepcomp_lib.rs
+++ b/src/test/run-pass/auxiliary/sepcomp_lib.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib
+// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib -g
 
 pub mod a {
     pub fn one() -> usize {
diff --git a/src/test/run-pass/debuginfo-lto.rs b/src/test/run-pass/debuginfo-lto.rs
new file mode 100644
index 00000000000..c29cfafe438
--- /dev/null
+++ b/src/test/run-pass/debuginfo-lto.rs
@@ -0,0 +1,33 @@
+// Copyright 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.
+
+// This test case makes sure that we don't run into LLVM's dreaded
+// "possible ODR violation" assertion when compiling with LTO + Debuginfo.
+// It covers cases that have traditionally been prone to cause this error.
+// If new cases emerge, add them to this file.
+
+// aux-build:debuginfo-lto-aux.rs
+// compile-flags: -C lto -g
+// no-prefer-dynamic
+
+extern crate debuginfo_lto_aux;
+
+fn some_fn(x: i32) -> i32 {
+    x + 1
+}
+
+fn main() {
+    let i = 0;
+    let _ = debuginfo_lto_aux::mk_struct_with_lt(&i);
+    let _ = debuginfo_lto_aux::mk_regular_struct(1);
+    let _ = debuginfo_lto_aux::take_fn(some_fn, 1);
+    let _ = debuginfo_lto_aux::with_closure(22);
+    let _ = debuginfo_lto_aux::generic_fn(0f32);
+}
diff --git a/src/test/run-pass/sepcomp-lib-lto.rs b/src/test/run-pass/sepcomp-lib-lto.rs
index b159b128333..f3e52fbd32f 100644
--- a/src/test/run-pass/sepcomp-lib-lto.rs
+++ b/src/test/run-pass/sepcomp-lib-lto.rs
@@ -12,7 +12,7 @@
 // separately compiled.
 
 // aux-build:sepcomp_lib.rs
-// compile-flags: -C lto
+// compile-flags: -C lto -g
 // no-prefer-dynamic
 // ignore-android FIXME #18800