|
| 1 | +// Test that #[inline] functions still get inlined across compilation unit |
| 2 | +// boundaries. Compilation should produce three IR files, but only the two |
| 3 | +// compilation units that have a usage of the #[inline] function should |
| 4 | +// contain a definition. Also, the non-#[inline] function should be defined |
| 5 | +// in only one compilation unit. |
| 6 | +// See https://github.com/rust-lang/rust/pull/16367 |
| 7 | + |
| 8 | +use run_make_support::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files}; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run(); |
| 12 | + let re = regex::Regex::new(r#"define\ i32\ .*inlined"#).unwrap(); |
| 13 | + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 0); |
| 14 | + let re = regex::Regex::new(r#"define\ internal\ .*inlined"#).unwrap(); |
| 15 | + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2); |
| 16 | + let re = regex::Regex::new(r#"define\ hidden\ i32\ .*normal"#).unwrap(); |
| 17 | + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 1); |
| 18 | + let re = regex::Regex::new(r#"declare\ hidden\ i32\ .*normal"#).unwrap(); |
| 19 | + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2); |
| 20 | +} |
| 21 | + |
| 22 | +fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { |
| 23 | + let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext)); |
| 24 | + |
| 25 | + let mut count = 0; |
| 26 | + for file in fetched_files { |
| 27 | + let content = fs_wrapper::read_to_string(file); |
| 28 | + count += content.lines().filter(|line| re.is_match(&line)).count(); |
| 29 | + } |
| 30 | + |
| 31 | + count |
| 32 | +} |
0 commit comments