Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcibly disable optimizations in backtrace-debuginfo #48090

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/test/run-pass/backtrace-debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
// Unfortunately, LLVM has no "disable" option for this, so we have to set
// "enable" to 0 instead.

// compile-flags:-g -Cllvm-args=-enable-tail-merge=0
// compile-flags:-g -Cllvm-args=-enable-tail-merge=0 -Cllvm-args=-opt-bisect-limit=0
// ignore-pretty issue #37195
// ignore-cloudabi spawning processes is not supported
// ignore-emscripten spawning processes is not supported

// note that above `-opt-bisect-limit=0` is used to basically disable
// optimizations

use std::env;

#[path = "backtrace-debuginfo-aux.rs"] mod aux;
Expand Down Expand Up @@ -114,25 +117,34 @@ fn outer(mut counter: i32, main_pos: Pos) {
inner_inlined(&mut counter, main_pos, pos!());
}

fn check_trace(output: &str, error: &str) {
fn check_trace(output: &str, error: &str) -> Result<(), String> {
// reverse the position list so we can start with the last item (which was the first line)
let mut remaining: Vec<&str> = output.lines().map(|s| s.trim()).rev().collect();

assert!(error.contains("stack backtrace"), "no backtrace in the error: {}", error);
if !error.contains("stack backtrace") {
return Err(format!("no backtrace found in stderr:\n{}", error))
}
for line in error.lines() {
if !remaining.is_empty() && line.contains(remaining.last().unwrap()) {
remaining.pop();
}
}
assert!(remaining.is_empty(),
"trace does not match position list: {}\n---\n{}", error, output);
if !remaining.is_empty() {
return Err(format!("trace does not match position list\n\
still need to find {:?}\n\n\
--- stdout\n{}\n\
--- stderr\n{}",
remaining, output, error))
}
Ok(())
}

fn run_test(me: &str) {
use std::str;
use std::process::Command;

let mut i = 0;
let mut errors = Vec::new();
loop {
let out = Command::new(me)
.env("RUST_BACKTRACE", "full")
Expand All @@ -143,10 +155,20 @@ fn run_test(me: &str) {
assert!(output.contains("done."), "bad output for successful run: {}", output);
break;
} else {
check_trace(output, error);
if let Err(e) = check_trace(output, error) {
errors.push(e);
}
}
i += 1;
}
if errors.len() > 0 {
for error in errors {
println!("---------------------------------------");
println!("{}", error);
}

panic!("found some errors");
}
}

#[inline(never)]
Expand Down