Skip to content

Commit 82e48a5

Browse files
jtmott-intelzmodem
authored andcommitted
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 (cherry picked from commit ca77ab4)
1 parent 0c37a91 commit 82e48a5

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
@@ -6021,9 +6021,8 @@ def err_func_def_incomplete_result : Error<
60216021
def err_atomic_specifier_bad_type
60226022
: Error<"_Atomic cannot be applied to "
60236023
"%select{incomplete |array |function |reference |atomic |qualified "
6024-
"|sizeless ||integer |integer }0type "
6025-
"%1 %select{|||||||which is not trivially copyable|with less than "
6026-
"1 byte of precision|with a non power of 2 precision}0">;
6024+
"|sizeless ||integer }0type "
6025+
"%1 %select{|||||||which is not trivially copyable|}0">;
60276026

60286027
// Expressions.
60296028
def ext_sizeof_alignof_function_type : Extension<
@@ -7941,6 +7940,8 @@ def err_atomic_exclusive_builtin_pointer_size : Error<
79417940
" 1,2,4 or 8 byte type (%0 invalid)">;
79427941
def err_atomic_builtin_ext_int_size : Error<
79437942
"Atomic memory operand must have a power-of-two size">;
7943+
def err_atomic_builtin_ext_int_prohibit : Error<
7944+
"argument to atomic builtin of type '_ExtInt' is not supported">;
79447945
def err_atomic_op_needs_atomic : Error<
79457946
"address argument to atomic operation must be a pointer to _Atomic "
79467947
"type (%0 invalid)">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,6 +4956,11 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
49564956
? 0
49574957
: 1);
49584958

4959+
if (ValType->isExtIntType()) {
4960+
Diag(Ptr->getExprLoc(), diag::err_atomic_builtin_ext_int_prohibit);
4961+
return ExprError();
4962+
}
4963+
49594964
return AE;
49604965
}
49614966

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8880,11 +8880,8 @@ QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
88808880
else if (!T.isTriviallyCopyableType(Context))
88818881
// Some other non-trivially-copyable type (probably a C++ class)
88828882
DisallowedKind = 7;
8883-
else if (auto *ExtTy = T->getAs<ExtIntType>()) {
8884-
if (ExtTy->getNumBits() < 8)
8883+
else if (T->isExtIntType()) {
88858884
DisallowedKind = 8;
8886-
else if (!llvm::isPowerOf2_32(ExtTy->getNumBits()))
8887-
DisallowedKind = 9;
88888885
}
88898886

88908887
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)