This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Tweak atomic
and atomic_ref
to match specification's constructor requirements
#219
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
94 changes: 94 additions & 0 deletions
94
.upstream-tests/test/std/atomics/atomics.types.generic/atomic_copyable.pass.cpp
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,94 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// UNSUPPORTED: libcpp-has-no-threads, pre-sm-60 | ||
// UNSUPPORTED: windows && pre-sm-70 | ||
|
||
// NOTE: atomic<> of a TriviallyCopyable class is wrongly rejected by older | ||
// clang versions. It was fixed right before the llvm 3.5 release. See PR18097. | ||
// XFAIL: apple-clang-6.0, clang-3.4, clang-3.3 | ||
|
||
// <cuda/std/atomic> | ||
|
||
#include <cuda/std/atomic> | ||
#include <cuda/std/utility> | ||
#include <cuda/std/cassert> | ||
// #include <cuda/std/thread> // for thread_id | ||
// #include <cuda/std/chrono> // for nanoseconds | ||
|
||
#include "test_macros.h" | ||
|
||
template <class T> | ||
__host__ __device__ | ||
void test_not_copy_constructible() { | ||
static_assert(!cuda::std::is_constructible<T, T&&>(), ""); | ||
static_assert(!cuda::std::is_constructible<T, const T&>(), ""); | ||
static_assert(!cuda::std::is_assignable<T, T&&>(), ""); | ||
static_assert(!cuda::std::is_assignable<T, const T&>(), ""); | ||
} | ||
|
||
template <class T> | ||
__host__ __device__ | ||
void test_copy_constructible() { | ||
static_assert(cuda::std::is_constructible<T, T&&>(), ""); | ||
static_assert(cuda::std::is_constructible<T, const T&>(), ""); | ||
static_assert(!cuda::std::is_assignable<T, T&&>(), ""); | ||
static_assert(!cuda::std::is_assignable<T, const T&>(), ""); | ||
} | ||
|
||
template <class T, class A> | ||
__host__ __device__ | ||
void test_atomic_ref_copy_ctor() { | ||
A val = 0; | ||
|
||
T t0(val); | ||
T t1(t0); | ||
|
||
t0++; | ||
t1++; | ||
|
||
assert(t1.load() == 2); | ||
} | ||
|
||
template <class T, class A> | ||
__host__ __device__ | ||
void test_atomic_ref_move_ctor() { | ||
A val = 0; | ||
|
||
T t0(val); | ||
t0++; | ||
|
||
T t1(cuda::std::move(t0)); | ||
t1++; | ||
|
||
assert(t1.load() == 2); | ||
} | ||
|
||
int main(int, char**) | ||
{ | ||
test_not_copy_constructible<cuda::std::atomic<int>>(); | ||
test_not_copy_constructible<cuda::atomic<int>>(); | ||
|
||
|
||
test_copy_constructible<cuda::std::atomic_ref<int>>(); | ||
test_copy_constructible<cuda::atomic_ref<int>>(); | ||
|
||
test_atomic_ref_copy_ctor<cuda::std::atomic_ref<int>, int>(); | ||
test_atomic_ref_copy_ctor<cuda::atomic_ref<int>, int>(); | ||
test_atomic_ref_copy_ctor<const cuda::std::atomic_ref<int>, int>(); | ||
test_atomic_ref_copy_ctor<const cuda::atomic_ref<int>, int>(); | ||
|
||
test_atomic_ref_move_ctor<cuda::std::atomic_ref<int>, int>(); | ||
test_atomic_ref_move_ctor<cuda::atomic_ref<int>, int>(); | ||
test_atomic_ref_move_ctor<const cuda::std::atomic_ref<int>, int>(); | ||
test_atomic_ref_move_ctor<const cuda::atomic_ref<int>, int>(); | ||
// test(cuda::std::this_thread::get_id()); | ||
// test(cuda::std::chrono::nanoseconds(2)); | ||
|
||
return 0; | ||
} |
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
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.
What about copy assignment? We should probably just rule of 0 it here and be explicit about the move ctor/assignment too?
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.
Good catch, seems like we've also lost that at some point (probably also in the refactor?).
@wmaxey seems like upstream deletes assignments directly in atomic and we don't, but I guess doing it in the base class is fine too?
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.
My thought process was:
__atomic_base
implements the behavior thatatomic
should inherit. This way if we 'rule of zero'atomic
we should get the correct behavior.We just don't have tests enforcing that bit of the standard so it was missed. 👎