Skip to content

Commit eb3c932

Browse files
committed
rewrite cross-lang-lto-clang to rmake
1 parent 4db3d12 commit eb3c932

File tree

6 files changed

+126
-29
lines changed

6 files changed

+126
-29
lines changed

src/tools/run-make-support/src/assertion_helpers.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::panic;
44
use std::path::Path;
55

6-
use crate::fs;
6+
use crate::{fs, regex};
77

88
/// Assert that `actual` is equal to `expected`.
99
#[track_caller]
@@ -47,6 +47,36 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
4747
}
4848
}
4949

50+
/// Assert that `haystack` contains the regex pattern `needle`.
51+
#[track_caller]
52+
pub fn assert_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
53+
let haystack = haystack.as_ref();
54+
let needle = needle.as_ref();
55+
let re = regex::Regex::new(needle).unwrap();
56+
if !re.is_match(haystack) {
57+
eprintln!("=== HAYSTACK ===");
58+
eprintln!("{}", haystack);
59+
eprintln!("=== NEEDLE ===");
60+
eprintln!("{}", needle);
61+
panic!("needle was not found in haystack");
62+
}
63+
}
64+
65+
/// Assert that `haystack` does not contain the regex pattern `needle`.
66+
#[track_caller]
67+
pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
68+
let haystack = haystack.as_ref();
69+
let needle = needle.as_ref();
70+
let re = regex::Regex::new(needle).unwrap();
71+
if re.is_match(haystack) {
72+
eprintln!("=== HAYSTACK ===");
73+
eprintln!("{}", haystack);
74+
eprintln!("=== NEEDLE ===");
75+
eprintln!("{}", needle);
76+
panic!("needle was unexpectedly found in haystack");
77+
}
78+
}
79+
5080
/// Assert that all files in `dir1` exist and have the same content in `dir2`
5181
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
5282
let dir2 = dir2.as_ref();

src/tools/run-make-support/src/command.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{ffi, panic};
77
use build_helper::drop_bomb::DropBomb;
88

99
use crate::util::handle_failed_output;
10-
use crate::{assert_contains, assert_equals, assert_not_contains};
10+
use crate::{
11+
assert_contains, assert_contains_regex, assert_equals, assert_not_contains,
12+
assert_not_contains_regex,
13+
};
1114

1215
/// This is a custom command wrapper that simplifies working with commands and makes it easier to
1316
/// ensure that we check the exit status of executed processes.
@@ -191,13 +194,27 @@ impl CompletedProcess {
191194
self
192195
}
193196

197+
/// Checks that `stdout` does not contain the regex pattern `unexpected`.
198+
#[track_caller]
199+
pub fn assert_stdout_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
200+
assert_not_contains_regex(&self.stdout_utf8(), unexpected);
201+
self
202+
}
203+
194204
/// Checks that `stdout` contains `expected`.
195205
#[track_caller]
196206
pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
197207
assert_contains(&self.stdout_utf8(), expected);
198208
self
199209
}
200210

211+
/// Checks that `stdout` contains the regex pattern `expected`.
212+
#[track_caller]
213+
pub fn assert_stdout_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
214+
assert_contains_regex(&self.stdout_utf8(), expected);
215+
self
216+
}
217+
201218
/// Checks that trimmed `stderr` matches trimmed `expected`.
202219
#[track_caller]
203220
pub fn assert_stderr_equals<S: AsRef<str>>(&self, expected: S) -> &Self {
@@ -212,13 +229,27 @@ impl CompletedProcess {
212229
self
213230
}
214231

232+
/// Checks that `stderr` contains the regex pattern `expected`.
233+
#[track_caller]
234+
pub fn assert_stderr_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
235+
assert_contains_regex(&self.stderr_utf8(), expected);
236+
self
237+
}
238+
215239
/// Checks that `stderr` does not contain `unexpected`.
216240
#[track_caller]
217241
pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
218242
assert_not_contains(&self.stdout_utf8(), unexpected);
219243
self
220244
}
221245

246+
/// Checks that `stderr` does not contain the regex pattern `unexpected`.
247+
#[track_caller]
248+
pub fn assert_stderr_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
249+
assert_not_contains_regex(&self.stdout_utf8(), unexpected);
250+
self
251+
}
252+
222253
#[track_caller]
223254
pub fn assert_exit_code(&self, code: i32) -> &Self {
224255
assert!(self.output.status.code() == Some(code));

src/tools/run-make-support/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ pub use path_helpers::{
8484
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
8585

8686
pub use assertion_helpers::{
87-
assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
87+
assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
88+
assert_not_contains, assert_not_contains_regex,
8889
};
8990

9091
pub use string::{

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/cat-and-grep-sanity-check/Makefile
33
run-make/cdylib-dylib-linkage/Makefile
4-
run-make/cross-lang-lto-clang/Makefile
54
run-make/cross-lang-lto-pgo-smoketest/Makefile
65
run-make/cross-lang-lto-upstream-rlibs/Makefile
76
run-make/cross-lang-lto/Makefile

tests/run-make/cross-lang-lto-clang/Makefile

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This test checks that cross-language inlining actually works by checking
2+
// the generated machine code.
3+
// See https://github.com/rust-lang/rust/pull/57514
4+
5+
//@ needs-force-clang-based-tests
6+
// FIXME(#126180): This test doesn't actually run anywhere, because the only
7+
// CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
8+
9+
use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, rustc, static_lib_name};
10+
11+
fn main() {
12+
rustc()
13+
.linker_plugin_lto("on")
14+
.output(static_lib_name("rustlib-xlto"))
15+
.opt_level("2")
16+
.codegen_units(1)
17+
.input("rustlib.rs")
18+
.run();
19+
clang()
20+
.lto("thin")
21+
.use_ld("lld")
22+
.arg("-lrustlib-xlto")
23+
.out_exe("cmain")
24+
.input("cmain.c")
25+
.arg("-O3")
26+
.run();
27+
// Make sure we don't find a call instruction to the function we expect to
28+
// always be inlined.
29+
llvm_objdump()
30+
.arg("-d")
31+
.input("cmain")
32+
.run()
33+
.assert_stdout_not_contains_regex("call.*rust_always_inlined");
34+
// As a sanity check, make sure we do find a call instruction to a
35+
// non-inlined function
36+
llvm_objdump()
37+
.arg("-d")
38+
.input("cmain")
39+
.run()
40+
.assert_stdout_contains_regex("call.*rust_never_inlined");
41+
clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
42+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
43+
rustc()
44+
.linker_plugin_lto("on")
45+
.opt_level("2")
46+
.linker(&env_var("CLANG"))
47+
.link_arg("-fuse-ld=lld")
48+
.input("main.rs")
49+
.output("rsmain")
50+
.run();
51+
llvm_objdump()
52+
.arg("-d")
53+
.input("rsmain")
54+
.run()
55+
.assert_stdout_not_contains_regex("call.*c_always_inlined");
56+
llvm_objdump()
57+
.arg("-d")
58+
.input("rsmain")
59+
.run()
60+
.assert_stdout_contains_regex("call.*c_never_inlined");
61+
}

0 commit comments

Comments
 (0)