forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#5028 - krishna-veerareddy:issue-5026-mem-orde…
…ring-fences, r=phansch Detect usage of invalid atomic ordering in memory fences Detect usage of `core::sync::atomic::{fence, compiler_fence}` with `Ordering::Relaxed` and suggest valid alternatives. changelog: Extend `invalid_atomic_ordering` to lint memory fences Fixes rust-lang#5026
- Loading branch information
Showing
4 changed files
with
104 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![warn(clippy::invalid_atomic_ordering)] | ||
|
||
use std::sync::atomic::{compiler_fence, fence, Ordering}; | ||
|
||
fn main() { | ||
// Allowed fence ordering modes | ||
fence(Ordering::Acquire); | ||
fence(Ordering::Release); | ||
fence(Ordering::AcqRel); | ||
fence(Ordering::SeqCst); | ||
|
||
// Disallowed fence ordering modes | ||
fence(Ordering::Relaxed); | ||
|
||
compiler_fence(Ordering::Acquire); | ||
compiler_fence(Ordering::Release); | ||
compiler_fence(Ordering::AcqRel); | ||
compiler_fence(Ordering::SeqCst); | ||
compiler_fence(Ordering::Relaxed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error: memory fences cannot have `Relaxed` ordering | ||
--> $DIR/atomic_ordering_fence.rs:13:11 | ||
| | ||
LL | fence(Ordering::Relaxed); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` | ||
= help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` | ||
|
||
error: memory fences cannot have `Relaxed` ordering | ||
--> $DIR/atomic_ordering_fence.rs:19:20 | ||
| | ||
LL | compiler_fence(Ordering::Relaxed); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` | ||
|
||
error: aborting due to 2 previous errors | ||
|