Skip to content

Commit 36ebd26

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd083adb068e7' from llvm.org/master into apple/master
2 parents 33b6a78 + d083adb commit 36ebd26

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8080,6 +8080,8 @@ def err_atomic_builtin_pointer_size : Error<
80808080
def err_atomic_exclusive_builtin_pointer_size : Error<
80818081
"address argument to load or store exclusive builtin must be a pointer to"
80828082
" 1,2,4 or 8 byte type (%0 invalid)">;
8083+
def err_atomic_builtin_ext_int_size : Error<
8084+
"Atomic memory operand must have a power-of-two size">;
80838085
def err_atomic_op_needs_atomic : Error<
80848086
"address argument to atomic operation must be a pointer to _Atomic "
80858087
"type (%0 invalid)">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5675,6 +5675,15 @@ Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) {
56755675
// gracefully.
56765676
TheCall->setType(ResultType);
56775677

5678+
// Prohibit use of _ExtInt with atomic builtins.
5679+
// The arguments would have already been converted to the first argument's
5680+
// type, so only need to check the first argument.
5681+
const auto *ExtIntValType = ValType->getAs<ExtIntType>();
5682+
if (ExtIntValType && !llvm::isPowerOf2_64(ExtIntValType->getNumBits())) {
5683+
Diag(FirstArg->getExprLoc(), diag::err_atomic_builtin_ext_int_size);
5684+
return ExprError();
5685+
}
5686+
56785687
return TheCallResult;
56795688
}
56805689

clang/test/Sema/builtins.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,42 @@ void test21(const int *ptr) {
281281
__atomic_fetch_add(ptr, 1, 0); // expected-error {{address argument to atomic operation must be a pointer to non-const type ('const int *' invalid)}}
282282
}
283283

284+
void test_ei_i42i(_ExtInt(42) *ptr, int value) {
285+
__sync_fetch_and_add(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
286+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
287+
__sync_nand_and_fetch(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
288+
}
289+
290+
void test_ei_i64i(_ExtInt(64) *ptr, int value) {
291+
__sync_fetch_and_add(ptr, value); // expect success
292+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
293+
__sync_nand_and_fetch(ptr, value); // expect success
294+
}
295+
296+
void test_ei_ii42(int *ptr, _ExtInt(42) value) {
297+
__sync_fetch_and_add(ptr, value); // expect success
298+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
299+
__sync_nand_and_fetch(ptr, value); // expect success
300+
}
301+
302+
void test_ei_ii64(int *ptr, _ExtInt(64) value) {
303+
__sync_fetch_and_add(ptr, value); // expect success
304+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
305+
__sync_nand_and_fetch(ptr, value); // expect success
306+
}
307+
308+
void test_ei_i42i42(_ExtInt(42) *ptr, _ExtInt(42) value) {
309+
__sync_fetch_and_add(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
310+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
311+
__sync_nand_and_fetch(ptr, value); // expected-error {{Atomic memory operand must have a power-of-two size}}
312+
}
313+
314+
void test_ei_i64i64(_ExtInt(64) *ptr, _ExtInt(64) value) {
315+
__sync_fetch_and_add(ptr, value); // expect success
316+
// expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}}
317+
__sync_nand_and_fetch(ptr, value); // expect success
318+
}
319+
284320
void test22(void) {
285321
(void)__builtin_signbit(); // expected-error{{too few arguments to function call, expected 1, have 0}}
286322
(void)__builtin_signbit(1.0, 2.0, 3.0); // expected-error{{too many arguments to function call, expected 1, have 3}}

0 commit comments

Comments
 (0)