Skip to content

Commit

Permalink
Rollup merge of #111469 - Dushistov:fix-coverage-data-race, r=wesleyw…
Browse files Browse the repository at this point in the history
…iser

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)
```
  • Loading branch information
Dylan-DPC committed May 13, 2023
2 parents 05ca3e3 + 6b58ff5 commit 770fd73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ LLVMRustOptimize(
if (InstrProfileOutput) {
Options.InstrProfileOutput = InstrProfileOutput;
}
// cargo run tests in multhreading mode by default
// so use atomics for coverage counters
Options.Atomic = true;
MPM.addPass(InstrProfiling(Options, false));
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/coverage-llvmir/filecheck.testprog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CHECK-SAME: section "llvm.metadata"
CHECK: [[DEFINE_INTERNAL]] { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} {
CHECK-NEXT: start:
CHECK-NOT: [[DEFINE_INTERNAL]]
CHECK: %pgocount = load i64, {{i64\*|ptr}}
CHECK: atomicrmw add ptr
CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called,

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

0 comments on commit 770fd73

Please sign in to comment.