Skip to content

Commit 0c19c63

Browse files
committed
Convert tests/run-make/instrument-coverage to an ordinary codegen test
This test was already very close to being an ordinary codegen test, except that it needed some extra logic to set a few variables based on (target) platform characteristics. Now that we have support for `//@ filecheck-flags:`, we can instead set those variables using the normal test revisions mechanism.
1 parent c1889b5 commit 0c19c63

File tree

4 files changed

+121
-152
lines changed

4 files changed

+121
-152
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//@ edition: 2021
2+
//@ needs-profiler-support
3+
//@ compile-flags: -Cinstrument-coverage -Copt-level=0
4+
//@ filecheck-flags: '-DDEFINE_INTERNAL=define internal'
5+
//@ revisions: LINUX DARWIN WINDOWS
6+
7+
//@ [LINUX] only-linux
8+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_DATA=__llvm_prf_data
9+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_NAME=__llvm_prf_names
10+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_CNTS=__llvm_prf_cnts
11+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_COVMAP=__llvm_covmap
12+
//@ [LINUX] filecheck-flags: -DINSTR_PROF_COVFUN=__llvm_covfun
13+
//@ [LINUX] filecheck-flags: '-DCOMDAT_IF_SUPPORTED=, comdat'
14+
15+
//@ [DARWIN] only-macos
16+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_DATA=__DATA,__llvm_prf_data,regular,live_support
17+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_NAME=__DATA,__llvm_prf_names
18+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_CNTS=__DATA,__llvm_prf_cnts
19+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_COVMAP=__LLVM_COV,__llvm_covmap
20+
//@ [DARWIN] filecheck-flags: -DINSTR_PROF_COVFUN=__LLVM_COV,__llvm_covfun
21+
//@ [DARWIN] filecheck-flags: -DCOMDAT_IF_SUPPORTED=
22+
23+
//@ [WINDOWS] only-windows
24+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_DATA=.lprfd$M
25+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_NAME=.lprfn$M
26+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_CNTS=.lprfc$M
27+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_COVMAP=.lcovmap$M
28+
//@ [WINDOWS] filecheck-flags: -DINSTR_PROF_COVFUN=.lcovfun$M
29+
//@ [WINDOWS] filecheck-flags: '-DCOMDAT_IF_SUPPORTED=, comdat'
30+
31+
// ignore-tidy-linelength
32+
33+
pub fn will_be_called() -> &'static str {
34+
let val = "called";
35+
println!("{}", val);
36+
val
37+
}
38+
39+
pub fn will_not_be_called() -> bool {
40+
println!("should not have been called");
41+
false
42+
}
43+
44+
pub fn print<T>(left: &str, value: T, right: &str)
45+
where
46+
T: std::fmt::Display,
47+
{
48+
println!("{}{}{}", left, value, right);
49+
}
50+
51+
pub fn wrap_with<F, T>(inner: T, should_wrap: bool, wrapper: F)
52+
where
53+
F: FnOnce(&T)
54+
{
55+
if should_wrap {
56+
wrapper(&inner)
57+
}
58+
}
59+
60+
fn main() {
61+
let less = 1;
62+
let more = 100;
63+
64+
if less < more {
65+
wrap_with(will_be_called(), less < more, |inner| print(" ***", inner, "*** "));
66+
wrap_with(will_be_called(), more < less, |inner| print(" ***", inner, "*** "));
67+
} else {
68+
wrap_with(will_not_be_called(), true, |inner| print("wrapped result is: ", inner, ""));
69+
}
70+
}
71+
72+
// Check for metadata, variables, declarations, and function definitions injected
73+
// into LLVM IR when compiling with -Cinstrument-coverage.
74+
75+
// WINDOWS: $__llvm_profile_runtime_user = comdat any
76+
77+
// CHECK: @__llvm_coverage_mapping = private constant
78+
// CHECK-SAME: section "[[INSTR_PROF_COVMAP]]", align 8
79+
80+
// CHECK: @__covrec_{{[A-F0-9]+}}u = linkonce_odr hidden constant
81+
// CHECK-SAME: section "[[INSTR_PROF_COVFUN]]"[[COMDAT_IF_SUPPORTED]], align 8
82+
83+
// WINDOWS: @__llvm_profile_runtime = external{{.*}}global i32
84+
85+
// CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = {{private|internal}} global
86+
// CHECK-SAME: section "[[INSTR_PROF_CNTS]]"{{.*}}, align 8
87+
88+
// CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = {{private|internal}} global
89+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called
90+
// CHECK-SAME: section "[[INSTR_PROF_DATA]]"{{.*}}, align 8
91+
92+
// CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main = {{private|internal}} global
93+
// CHECK-SAME: section "[[INSTR_PROF_CNTS]]"{{.*}}, align 8
94+
95+
// CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog4main = {{private|internal}} global
96+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main
97+
// CHECK-SAME: section "[[INSTR_PROF_DATA]]"{{.*}}, align 8
98+
99+
// CHECK: @__llvm_prf_nm = private constant
100+
// CHECK-SAME: section "[[INSTR_PROF_NAME]]", align 1
101+
102+
// CHECK: @llvm.used = appending global
103+
// CHECK-SAME: @__llvm_coverage_mapping
104+
// CHECK-SAME: @__llvm_prf_nm
105+
// CHECK-SAME: section "llvm.metadata"
106+
107+
// CHECK: [[DEFINE_INTERNAL]] { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} {
108+
// CHECK-NEXT: start:
109+
// CHECK-NOT: [[DEFINE_INTERNAL]]
110+
// CHECK: atomicrmw add ptr
111+
// CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called,
112+
113+
// CHECK: declare void @llvm.instrprof.increment(ptr, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]]
114+
115+
// WINDOWS: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() #[[LLVM_PROFILE_RUNTIME_USER_ATTR:[0-9]+]] comdat {
116+
// WINDOWS-NEXT: %1 = load i32, ptr @__llvm_profile_runtime
117+
// WINDOWS-NEXT: ret i32 %1
118+
// WINDOWS-NEXT: }
119+
120+
// CHECK: attributes #[[LLVM_INSTRPROF_INCREMENT_ATTR]] = { nounwind }
121+
// WINDOWS: attributes #[[LLVM_PROFILE_RUNTIME_USER_ATTR]] = { noinline }

tests/run-make/coverage-llvmir/Makefile

-64
This file was deleted.

tests/run-make/coverage-llvmir/filecheck.testprog.txt

-50
This file was deleted.

tests/run-make/coverage-llvmir/testprog.rs

-38
This file was deleted.

0 commit comments

Comments
 (0)