Commit 7fbb72b
committed
[mlir] DistinctAttributeAllocator: fix race
The bitfields added in #128566 (`threadingIsEnabled : 1`
and `useThreadLocalAllocator : 1`) are accessed without
synchronization. Example tsan report:
```
WARNING: ThreadSanitizer: data race (pid=337)
Write of size 1 at 0x7260001d0ff0 by thread T224:
#0 disableThreadLocalStorage third_party/llvm/llvm-project/mlir/lib/IR/AttributeDetail.h:434:29
#1 mlir::MLIRContext::disableThreadLocalStorage(bool) third_party/llvm/llvm-project/mlir/lib/IR/MLIRContext.cpp:723:40
#2 mlir::PassManager::runWithCrashRecovery(mlir::Operation*, mlir::AnalysisManager) third_party/llvm/llvm-project/mlir/lib/Pass/PassCrashRecovery.cpp:423:8
[...]
Previous write of size 1 at 0x7260001d0ff0 by thread T222:
#0 disableThreadLocalStorage third_party/llvm/llvm-project/mlir/lib/IR/AttributeDetail.h:434:29
#1 mlir::MLIRContext::disableThreadLocalStorage(bool) third_party/llvm/llvm-project/mlir/lib/IR/MLIRContext.cpp:723:40
#2 mlir::PassManager::runWithCrashRecovery(mlir::Operation*, mlir::AnalysisManager) third_party/llvm/llvm-project/mlir/lib/Pass/PassCrashRecovery.cpp:423:8
```
Fix the race by serializing accesses to these fields with
the existing `allocatorMutex`.1 parent b246943 commit 7fbb72b
1 file changed
+12
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
416 | 417 | | |
417 | | - | |
418 | | - | |
| 418 | + | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| 426 | + | |
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| |||
431 | 432 | | |
432 | 433 | | |
433 | 434 | | |
| 435 | + | |
434 | 436 | | |
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
438 | | - | |
439 | | - | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
440 | 444 | | |
441 | 445 | | |
442 | 446 | | |
443 | 447 | | |
444 | 448 | | |
445 | 449 | | |
446 | 450 | | |
447 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
448 | 454 | | |
449 | 455 | | |
450 | 456 | | |
| |||
0 commit comments