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

compiletest: Remove the magic hacks for finding output with lto=thin #131524

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
56 changes: 6 additions & 50 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,71 +1780,28 @@ impl<'test> TestCx<'test> {
proc_res.fatal(None, || on_failure(*self));
}

fn get_output_file(&self, extension: &str) -> TargetLocation {
let thin_lto = self.props.compile_flags.iter().any(|s| s.ends_with("lto=thin"));
if thin_lto {
TargetLocation::ThisDirectory(self.output_base_dir())
} else {
// This works with both `--emit asm` (as default output name for the assembly)
// and `ptx-linker` because the latter can write output at requested location.
let output_path = self.output_base_name().with_extension(extension);

TargetLocation::ThisFile(output_path.clone())
}
}

fn get_filecheck_file(&self, extension: &str) -> PathBuf {
let thin_lto = self.props.compile_flags.iter().any(|s| s.ends_with("lto=thin"));
if thin_lto {
let name = self.testpaths.file.file_stem().unwrap().to_str().unwrap();
let canonical_name = name.replace('-', "_");
let mut output_file = None;
for entry in self.output_base_dir().read_dir().unwrap() {
if let Ok(entry) = entry {
let entry_path = entry.path();
let entry_file = entry_path.file_name().unwrap().to_str().unwrap();
if entry_file.starts_with(&format!("{}.{}", name, canonical_name))
&& entry_file.ends_with(extension)
{
assert!(
output_file.is_none(),
"thinlto doesn't support multiple cgu tests"
);
output_file = Some(entry_file.to_string());
}
}
}
if let Some(output_file) = output_file {
self.output_base_dir().join(output_file)
} else {
self.output_base_name().with_extension(extension)
}
} else {
self.output_base_name().with_extension(extension)
}
}

// codegen tests (using FileCheck)

fn compile_test_and_save_ir(&self) -> (ProcRes, PathBuf) {
let output_file = self.get_output_file("ll");
let output_path = self.output_base_name().with_extension("ll");
let input_file = &self.testpaths.file;
let rustc = self.make_compile_args(
input_file,
output_file,
TargetLocation::ThisFile(output_path.clone()),
Emit::LlvmIr,
AllowUnused::No,
LinkToAux::Yes,
Vec::new(),
);

let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
let output_path = self.get_filecheck_file("ll");
(proc_res, output_path)
}

fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
let output_file = self.get_output_file("s");
// This works with both `--emit asm` (as default output name for the assembly)
// and `ptx-linker` because the latter can write output at requested location.
let output_path = self.output_base_name().with_extension("s");
let input_file = &self.testpaths.file;

let mut emit = Emit::None;
Expand All @@ -1867,15 +1824,14 @@ impl<'test> TestCx<'test> {

let rustc = self.make_compile_args(
input_file,
output_file,
TargetLocation::ThisFile(output_path.clone()),
emit,
AllowUnused::No,
LinkToAux::Yes,
Vec::new(),
);

let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
let output_path = self.get_filecheck_file("s");
(proc_res, output_path)
}

Expand Down
7 changes: 0 additions & 7 deletions tests/assembly/thin-lto.rs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/codegen/thin-lto.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/coverage/thin-lto.cov-map

This file was deleted.

4 changes: 0 additions & 4 deletions tests/coverage/thin-lto.coverage

This file was deleted.

3 changes: 0 additions & 3 deletions tests/coverage/thin-lto.rs

This file was deleted.

Loading