Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Improve atomic_fetch_(add|sub).*.
While looking at the review comments in D103765 there was an oddity in the tests for the following functions: - atomic_fetch_add - atomic_fetch_add_explicit - atomic_fetch_sub - atomic_fetch_sub_explicit Libc++ allows usage of `atomic_fetch_add<int>(atomic<int*>*, atomic<int*>::difference_type);` MSVC and GCC reject this code: https://godbolt.org/z/9d8WzohbE This makes the atomic `fetch(add|sub).*` Standard conforming and removes the non-conforming extensions. Fixes PR47908 Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D103983
- Loading branch information
Showing
10 changed files
with
409 additions
and
182 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
76 changes: 76 additions & 0 deletions
76
...atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.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,76 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
// <atomic> | ||
|
||
// template <class T> | ||
// T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) | ||
// template <class T> | ||
// T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op); | ||
|
||
#include <atomic> | ||
|
||
void void_pointer() { | ||
{ | ||
volatile std::atomic<void*> obj; | ||
// expected-error@atomic:* {{incomplete type 'void' where a complete type is required}} | ||
std::atomic_fetch_add(&obj, 0); | ||
} | ||
{ | ||
std::atomic<void*> obj; | ||
// expected-error@atomic:* {{incomplete type 'void' where a complete type is required}} | ||
std::atomic_fetch_add(&obj, 0); | ||
} | ||
} | ||
|
||
struct Incomplete; | ||
|
||
void pointer_to_incomplete_type() { | ||
{ | ||
volatile std::atomic<Incomplete*> obj; | ||
// expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}} | ||
std::atomic_fetch_add(&obj, 0); | ||
} | ||
{ | ||
std::atomic<Incomplete*> obj; | ||
// expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}} | ||
std::atomic_fetch_add(&obj, 0); | ||
} | ||
} | ||
|
||
void function_pointer() { | ||
{ | ||
volatile std::atomic<void (*)(int)> fun; | ||
// expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}} | ||
std::atomic_fetch_add(&fun, 0); | ||
} | ||
{ | ||
std::atomic<void (*)(int)> fun; | ||
// expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}} | ||
std::atomic_fetch_add(&fun, 0); | ||
} | ||
} | ||
|
||
struct S { | ||
void fun(int); | ||
}; | ||
|
||
void member_function_pointer() { | ||
{ | ||
volatile std::atomic<void (S::*)(int)> fun; | ||
// expected-error@atomic:* {{no member named 'fetch_add' in}} | ||
std::atomic_fetch_add(&fun, 0); | ||
} | ||
{ | ||
std::atomic<void (S::*)(int)> fun; | ||
// expected-error@atomic:* {{no member named 'fetch_add' in}} | ||
std::atomic_fetch_add(&fun, 0); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...tomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.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,79 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
// <atomic> | ||
|
||
// template <class T> | ||
// T* | ||
// atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op, | ||
// memory_order m); | ||
// template <class T> | ||
// T* | ||
// atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m); | ||
|
||
#include <atomic> | ||
|
||
void void_pointer() { | ||
{ | ||
volatile std::atomic<void*> obj; | ||
// expected-error@atomic:* {{incomplete type 'void' where a complete type is required}} | ||
std::atomic_fetch_add_explicit(&obj, 0, std::memory_order_relaxed); | ||
} | ||
{ | ||
std::atomic<void*> obj; | ||
// expected-error@atomic:* {{incomplete type 'void' where a complete type is required}} | ||
std::atomic_fetch_add_explicit(&obj, 0, std::memory_order_relaxed); | ||
} | ||
} | ||
|
||
struct Incomplete; | ||
|
||
void pointer_to_incomplete_type() { | ||
{ | ||
volatile std::atomic<Incomplete*> obj; | ||
// expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}} | ||
std::atomic_fetch_add_explicit(&obj, 0, std::memory_order_relaxed); | ||
} | ||
{ | ||
std::atomic<Incomplete*> obj; | ||
// expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}} | ||
std::atomic_fetch_add_explicit(&obj, 0, std::memory_order_relaxed); | ||
} | ||
} | ||
|
||
void function_pointer() { | ||
{ | ||
volatile std::atomic<void (*)(int)> fun; | ||
// expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}} | ||
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed); | ||
} | ||
{ | ||
std::atomic<void (*)(int)> fun; | ||
// expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}} | ||
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed); | ||
} | ||
} | ||
|
||
struct S { | ||
void fun(int); | ||
}; | ||
|
||
void member_function_pointer() { | ||
{ | ||
volatile std::atomic<void (S::*)(int)> fun; | ||
// expected-error@atomic:* {{no member named 'fetch_add' in}} | ||
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed); | ||
} | ||
{ | ||
std::atomic<void (S::*)(int)> fun; | ||
// expected-error@atomic:* {{no member named 'fetch_add' in}} | ||
std::atomic_fetch_add_explicit(&fun, 0, std::memory_order_relaxed); | ||
} | ||
} |
Oops, something went wrong.
Should be libstdc++?