Skip to content

Commit 8609f47

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 b5c09d6 commit 8609f47

File tree

4 files changed

+120
-152
lines changed

4 files changed

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