Skip to content

Commit 473b0da

Browse files
committed
Review comments
1 parent e8b924b commit 473b0da

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ def AtomicNandFetch : AtomicBuiltin {
19801980
def AtomicTestAndSet : AtomicBuiltin {
19811981
let Spellings = ["__atomic_test_and_set"];
19821982
let Attributes = [NoThrow, CustomTypeChecking];
1983-
let Prototype = "void(...)";
1983+
let Prototype = "bool(...)";
19841984
}
19851985

19861986
def AtomicClear : AtomicBuiltin {

clang/lib/Sema/SemaChecking.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,13 +3690,13 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
36903690
GNUCmpXchg,
36913691

36923692
// bool __atomic_test_and_set(A *, int)
3693-
TestAndSet,
3693+
TestAndSetByte,
36943694

36953695
// void __atomic_clear(A *, int)
3696-
Clear,
3696+
ClearByte,
36973697
} Form = Init;
36983698

3699-
const unsigned NumForm = Clear + 1;
3699+
const unsigned NumForm = ClearByte + 1;
37003700
const unsigned NumArgs[] = {2, 2, 3, 3, 3, 3, 4, 5, 6, 2, 2};
37013701
const unsigned NumVals[] = {1, 0, 1, 1, 1, 1, 2, 2, 3, 0, 0};
37023702
// where:
@@ -3861,11 +3861,11 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
38613861
break;
38623862

38633863
case AtomicExpr::AO__atomic_test_and_set:
3864-
Form = TestAndSet;
3864+
Form = TestAndSetByte;
38653865
break;
38663866

38673867
case AtomicExpr::AO__atomic_clear:
3868-
Form = Clear;
3868+
Form = ClearByte;
38693869
break;
38703870
}
38713871

@@ -3926,7 +3926,7 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
39263926
}
39273927
}
39283928

3929-
if (Form != TestAndSet && Form != Clear) {
3929+
if (Form != TestAndSetByte && Form != ClearByte) {
39303930
// Pointer to object of size zero is not allowed.
39313931
if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
39323932
diag::err_incomplete_type))
@@ -3941,16 +3941,13 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
39413941
// The __atomic_clear and __atomic_test_and_set intrinsics accept any
39423942
// non-const pointer type, including void* and pointers to incomplete
39433943
// structs, but only access the first byte.
3944-
if (AtomTy.isVolatileQualified())
3945-
Ptr = ImpCastExprToType(
3946-
Ptr,
3947-
Context.getPointerType(Context.getVolatileType(Context.CharTy)),
3948-
CK_BitCast)
3949-
.get();
3950-
else
3951-
Ptr = ImpCastExprToType(Ptr, Context.getPointerType(Context.CharTy),
3952-
CK_BitCast)
3953-
.get();
3944+
AtomTy = Context.CharTy;
3945+
AtomTy = AtomTy.withCVRQualifiers(
3946+
pointerType->getPointeeType().getCVRQualifiers());
3947+
QualType PointerQT = Context.getPointerType(AtomTy);
3948+
pointerType = PointerQT->getAs<PointerType>();
3949+
Ptr = ImpCastExprToType(Ptr, PointerQT, CK_BitCast).get();
3950+
ValType = AtomTy;
39543951
}
39553952

39563953
// For an arithmetic operation, the implied arithmetic must be well-formed.
@@ -3995,8 +3992,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
39953992
return ExprError();
39963993
}
39973994

3998-
if (!IsC11 && Form != TestAndSet && Form != Clear &&
3999-
!AtomTy.isTriviallyCopyableType(Context) && !AtomTy->isScalarType()) {
3995+
if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
3996+
!AtomTy->isScalarType()) {
40003997
// For GNU atomics, require a trivially-copyable type. This is not part of
40013998
// the GNU atomics specification but we enforce it for consistency with
40023999
// other atomics which generally all require a trivially-copyable type. This
@@ -4030,9 +4027,9 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
40304027
ValType.removeLocalConst();
40314028
QualType ResultType = ValType;
40324029
if (Form == Copy || Form == LoadCopy || Form == GNUXchg || Form == Init ||
4033-
Form == Clear)
4030+
Form == ClearByte)
40344031
ResultType = Context.VoidTy;
4035-
else if (Form == C11CmpXchg || Form == GNUCmpXchg || Form == TestAndSet)
4032+
else if (Form == C11CmpXchg || Form == GNUCmpXchg || Form == TestAndSetByte)
40364033
ResultType = Context.BoolTy;
40374034

40384035
// The type of a parameter passed 'by value'. In the GNU atomics, such
@@ -4077,8 +4074,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
40774074
APIOrderedArgs.push_back(Args[1]); // Order
40784075
APIOrderedArgs.push_back(Args[3]); // OrderFail
40794076
break;
4080-
case TestAndSet:
4081-
case Clear:
4077+
case TestAndSetByte:
4078+
case ClearByte:
40824079
APIOrderedArgs.push_back(Args[1]); // Order
40834080
break;
40844081
}
@@ -4166,8 +4163,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
41664163
SubExprs.push_back(APIOrderedArgs[1]); // Val1
41674164
break;
41684165
case Load:
4169-
case TestAndSet:
4170-
case Clear:
4166+
case TestAndSetByte:
4167+
case ClearByte:
41714168
SubExprs.push_back(APIOrderedArgs[1]); // Order
41724169
break;
41734170
case LoadCopy:

clang/test/Sema/atomic-ops.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci,
293293
__atomic_clear(&flag, memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}}
294294
__atomic_clear(&flag, memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}}
295295
__atomic_clear(&flag, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}}
296+
_Bool lock;
297+
__atomic_test_and_set(lock, memory_order_acquire); // expected-error {{address argument to atomic builtin must be a pointer}}
298+
__atomic_clear(lock, memory_order_release); // expected-error {{address argument to atomic builtin must be a pointer}}
296299

297300
// These intrinsics accept any non-const pointer type (including
298301
// pointer-to-incomplete), and access the first byte.

0 commit comments

Comments
 (0)