-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Add -Watomic-memory-ordering diagnostic tests for atomic_ref
#130206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d14e446
Drop `assert.` prefix in tests for atomic_ref preconditions
dalg24 8ef8460
Add -Watomic-memory-ordering diagnostic tests for atomic_ref
dalg24 a2afe64
Revert "Drop `assert.` prefix in tests for atomic_ref preconditions"
dalg24 d5f455a
Missing line in license header
dalg24 c4adba6
Add missing first line in license header for libcxx/test/libcxx/atomi…
dalg24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
libcxx/test/libcxx/atomics/atomics.ref/assert.compare_exchange_strong.pass.cpp
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
libcxx/test/libcxx/atomics/atomics.ref/assert.compare_exchange_weak.pass.cpp
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
libcxx/test/libcxx/atomics/atomics.ref/compare_exchange_strong.verify.cpp
This file contains hidden or 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,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: diagnose-if-support | ||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
|
||
| // <atomic> | ||
|
|
||
| // bool compare_exchange_strong(T& expected, T desired, memory_order success, | ||
| // memory_order failure) const noexcept; | ||
| // | ||
| // Preconditions: failure is memory_order::relaxed, memory_order::consume, | ||
| // memory_order::acquire, or memory_order::seq_cst. | ||
|
|
||
| #include <atomic> | ||
|
|
||
| void test() { | ||
| using T = int; | ||
|
|
||
| T x(T(1)); | ||
| std::atomic_ref const a(x); | ||
|
|
||
| T expected(T(2)); | ||
| T const desired(T(3)); | ||
| std::memory_order const success = std::memory_order_relaxed; | ||
| // clang-format off | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_relaxed); | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_consume); | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_acquire); | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_seq_cst); | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| a.compare_exchange_strong(expected, desired, success, std::memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| // clang-format on | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
libcxx/test/libcxx/atomics/atomics.ref/compare_exchange_weak.verify.cpp
This file contains hidden or 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,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: diagnose-if-support | ||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
|
||
| // <atomic> | ||
|
|
||
| // bool compare_exchange_weak(T& expected, T desired, memory_order success, | ||
| // memory_order failure) const noexcept; | ||
| // | ||
| // Preconditions: failure is memory_order::relaxed, memory_order::consume, | ||
| // memory_order::acquire, or memory_order::seq_cst. | ||
|
|
||
| #include <atomic> | ||
|
|
||
| void test() { | ||
| using T = int; | ||
|
|
||
| T x(T(42)); | ||
| std::atomic_ref const a(x); | ||
|
|
||
| T expected(T(2)); | ||
| T const desired(T(3)); | ||
| std::memory_order const success = std::memory_order_relaxed; | ||
| // clang-format off | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_relaxed); | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_consume); | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_acquire); | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_seq_cst); | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| a.compare_exchange_weak(expected, desired, success, std::memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| // clang-format on | ||
| } |
This file contains hidden or 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,34 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: diagnose-if-support | ||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
|
||
| // <atomic> | ||
|
|
||
| // T load(memory_order order = memory_order::seq_cst) const noexcept; | ||
| // | ||
| // Preconditions: order is memory_order::relaxed, memory_order::consume, memory_order::acquire, or memory_order::seq_cst. | ||
|
|
||
| #include <atomic> | ||
|
|
||
| void test() { | ||
| using T = int; | ||
|
|
||
| T x(T(1)); | ||
| std::atomic_ref const a(x); | ||
|
|
||
| // clang-format off | ||
| (void)a.load(std::memory_order_relaxed); | ||
| (void)a.load(std::memory_order_consume); | ||
| (void)a.load(std::memory_order_acquire); | ||
| (void)a.load(std::memory_order_seq_cst); | ||
| (void)a.load(std::memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| (void)a.load(std::memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| // clang-format on | ||
| } |
This file contains hidden or 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,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: diagnose-if-support | ||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
|
||
| // <atomic> | ||
|
|
||
| // void store(T desired, memory_order order = memory_order::seq_cst) const noexcept; | ||
| // | ||
| // Preconditions: order is memory_order::relaxed, memory_order::release, or memory_order::seq_cst. | ||
|
|
||
| #include <atomic> | ||
|
|
||
| void test() { | ||
| using T = int; | ||
|
|
||
| T x(T(1)); | ||
| std::atomic_ref const a(x); | ||
|
|
||
| T const desired(T(2)); | ||
|
|
||
| // clang-format off | ||
| a.store(desired, std::memory_order_relaxed); | ||
| a.store(desired, std::memory_order_release); | ||
| a.store(desired, std::memory_order_seq_cst); | ||
| a.store(desired, std::memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| a.store(desired, std::memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| a.store(desired, std::memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| // clang-format on | ||
| } |
This file contains hidden or 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,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: diagnose-if-support | ||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
|
||
| // <atomic> | ||
|
|
||
| // void wait(T old, memory_order order = memory_order::seq_cst) const noexcept; | ||
| // | ||
| // Preconditions: order is memory_order::relaxed, memory_order::consume, memory_order::acquire, or memory_order::seq_cst. | ||
|
|
||
| #include <atomic> | ||
|
|
||
| void test() { | ||
| using T = int; | ||
|
|
||
| T x(T(1)); | ||
| std::atomic_ref const a(x); | ||
|
|
||
| T const old(T(2)); | ||
|
|
||
| // clang-format off | ||
| a.wait(old, std::memory_order_relaxed); | ||
| a.wait(old, std::memory_order_consume); | ||
| a.wait(old, std::memory_order_acquire); | ||
| a.wait(old, std::memory_order_seq_cst); | ||
| a.wait(old, std::memory_order_release); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| a.wait(old, std::memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}} | ||
| // clang-format on | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've dropped the first line of the license header when copy/pasting.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are missing in the
assert.*files as well. That's where I copy/pasted from.Want me to add as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that seems like a small enough drive-by change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done