Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
Copy link
Contributor

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.

Copy link
Member Author

@dalg24 dalg24 Mar 10, 2025

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?

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// 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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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
}
File renamed without changes.
33 changes: 33 additions & 0 deletions libcxx/test/libcxx/atomics/atomics.ref/load.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// 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
}
35 changes: 35 additions & 0 deletions libcxx/test/libcxx/atomics/atomics.ref/store.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// 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
}
35 changes: 35 additions & 0 deletions libcxx/test/libcxx/atomics/atomics.ref/wait.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// 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
}