Skip to content

Commit 770fd73

Browse files
authored
Rollup merge of #111469 - Dushistov:fix-coverage-data-race, r=wesleywiser
Fix data race in llvm source code coverage Fixes #91092 . Before this patch, increment of counters for code coverage looks like this: ``` movq .L__profc__RNvCsd6wgJFC5r19_3lib6bugaga+8(%rip), %rax addq $1, %rax movq %rax, .L__profc__RNvCsd6wgJFC5r19_3lib6bugaga+8(%rip) ``` after this patch: ``` lock incq .L__profc__RNvCs3JgIB2SjHh2_3lib6bugaga+8(%rip) ```
2 parents 05ca3e3 + 6b58ff5 commit 770fd73

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ LLVMRustOptimize(
745745
if (InstrProfileOutput) {
746746
Options.InstrProfileOutput = InstrProfileOutput;
747747
}
748+
// cargo run tests in multhreading mode by default
749+
// so use atomics for coverage counters
750+
Options.Atomic = true;
748751
MPM.addPass(InstrProfiling(Options, false));
749752
}
750753
);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CHECK-SAME: section "llvm.metadata"
3636
CHECK: [[DEFINE_INTERNAL]] { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} {
3737
CHECK-NEXT: start:
3838
CHECK-NOT: [[DEFINE_INTERNAL]]
39-
CHECK: %pgocount = load i64, {{i64\*|ptr}}
39+
CHECK: atomicrmw add ptr
4040
CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called,
4141

4242
CHECK: declare void @llvm.instrprof.increment({{i8\*|ptr}}, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]]

0 commit comments

Comments
 (0)