Skip to content

Commit ca77ab4

Browse files
committed
Disable use of _ExtInt with '__atomic' builtins
We're (temporarily) disabling ExtInt for the '__atomic' builtins so we can better design their behavior later. The idea is until we do an audit/design for the way atomic builtins are supposed to work with _ExtInt, we should leave them restricted so they don't limit our future options, such as by binding us to a sub-optimal implementation via ABI. Example after this change: $ cat test.c void f(_ExtInt(64) *ptr) { __atomic_fetch_add(ptr, 1, 0); } $ clang -c test.c test.c:2:22: error: argument to atomic builtin of type '_ExtInt' is not supported __atomic_fetch_add(ptr, 1, 0); ^ 1 error generated. Differential Revision: https://reviews.llvm.org/D84049
1 parent 3471520 commit ca77ab4

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6038,9 +6038,8 @@ def err_func_def_incomplete_result : Error<
60386038
def err_atomic_specifier_bad_type
60396039
: Error<"_Atomic cannot be applied to "
60406040
"%select{incomplete |array |function |reference |atomic |qualified "
6041-
"|sizeless ||integer |integer }0type "
6042-
"%1 %select{|||||||which is not trivially copyable|with less than "
6043-
"1 byte of precision|with a non power of 2 precision}0">;
6041+
"|sizeless ||integer }0type "
6042+
"%1 %select{|||||||which is not trivially copyable|}0">;
60446043

60456044
// Expressions.
60466045
def ext_sizeof_alignof_function_type : Extension<
@@ -7967,6 +7966,8 @@ def err_atomic_exclusive_builtin_pointer_size : Error<
79677966
" 1,2,4 or 8 byte type (%0 invalid)">;
79687967
def err_atomic_builtin_ext_int_size : Error<
79697968
"Atomic memory operand must have a power-of-two size">;
7969+
def err_atomic_builtin_ext_int_prohibit : Error<
7970+
"argument to atomic builtin of type '_ExtInt' is not supported">;
79707971
def err_atomic_op_needs_atomic : Error<
79717972
"address argument to atomic operation must be a pointer to _Atomic "
79727973
"type (%0 invalid)">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,6 +5050,11 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
50505050
? 0
50515051
: 1);
50525052

5053+
if (ValType->isExtIntType()) {
5054+
Diag(Ptr->getExprLoc(), diag::err_atomic_builtin_ext_int_prohibit);
5055+
return ExprError();
5056+
}
5057+
50535058
return AE;
50545059
}
50555060

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8963,11 +8963,8 @@ QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
89638963
else if (!T.isTriviallyCopyableType(Context))
89648964
// Some other non-trivially-copyable type (probably a C++ class)
89658965
DisallowedKind = 7;
8966-
else if (auto *ExtTy = T->getAs<ExtIntType>()) {
8967-
if (ExtTy->getNumBits() < 8)
8966+
else if (T->isExtIntType()) {
89688967
DisallowedKind = 8;
8969-
else if (!llvm::isPowerOf2_32(ExtTy->getNumBits()))
8970-
DisallowedKind = 9;
89718968
}
89728969

89738970
if (DisallowedKind != -1) {

clang/test/Sema/builtins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,16 @@ void test_ei_i42i(_ExtInt(42) *ptr, int value) {
285285
__sync_fetch_and_add(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
286286
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
287287
__sync_nand_and_fetch(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
288+
289+
__atomic_fetch_add(ptr, 1, 0); // expected-error {{argument to atomic builtin of type '_ExtInt' is not supported}}
288290
}
289291

290292
void test_ei_i64i(_ExtInt(64) *ptr, int value) {
291293
__sync_fetch_and_add(ptr, value); // expect success
292294
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
293295
__sync_nand_and_fetch(ptr, value); // expect success
296+
297+
__atomic_fetch_add(ptr, 1, 0); // expected-error {{argument to atomic builtin of type '_ExtInt' is not supported}}
294298
}
295299

296300
void test_ei_ii42(int *ptr, _ExtInt(42) value) {

clang/test/SemaCXX/ext-int.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ typedef _ExtInt(32) __attribute__((vector_size(16))) VecTy;
9191
_Complex _ExtInt(3) Cmplx;
9292

9393
// Reject cases of _Atomic:
94-
// expected-error@+1{{_Atomic cannot be applied to integer type '_ExtInt(4)' with less than 1 byte of precision}}
94+
// expected-error@+1{{_Atomic cannot be applied to integer type '_ExtInt(4)'}}
9595
_Atomic _ExtInt(4) TooSmallAtomic;
96-
// expected-error@+1{{_Atomic cannot be applied to integer type '_ExtInt(9)' with a non power of 2 precision}}
96+
// expected-error@+1{{_Atomic cannot be applied to integer type '_ExtInt(9)'}}
9797
_Atomic _ExtInt(9) NotPow2Atomic;
98+
// expected-error@+1{{_Atomic cannot be applied to integer type '_ExtInt(128)'}}
9899
_Atomic _ExtInt(128) JustRightAtomic;
99100

100101
// Test result types of Unary/Bitwise/Binary Operations:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: clang-11
2+
3+
#include <atomic>
4+
5+
int main(int, char**)
6+
{
7+
// expected-error@atomic:*1 {{_Atomic cannot be applied to integer type '_ExtInt(32)'}}
8+
std::atomic<_ExtInt(32)> x {42};
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)