Author: Aaron Ballman Date: 2023-04-20T10:24:22-04:00 New Revision: 63a82dd4eb0c23dbd4277a5ce2d5bfeda836aa64
URL: https://github.com/llvm/llvm-project/commit/63a82dd4eb0c23dbd4277a5ce2d5bfeda836aa64 DIFF: https://github.com/llvm/llvm-project/commit/63a82dd4eb0c23dbd4277a5ce2d5bfeda836aa64.diff LOG: [C11] Allow casting to an _Atomic-qualified type We were failing to strip off atomic qualification when forming the cast destination type, but properly stripping off cvr qualification. Now we accept atomic, qualified, or unqualified destination types. Note: the semantics of the cast still drop the qualifier, so such a cast does not result in an atomic rvalue. Fixes https://github.com/llvm/llvm-project/issues/39596 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaCast.cpp clang/test/Sema/atomic-expr.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1babd4d459f9b..febd47c1ef3fc 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -112,6 +112,8 @@ C Language Changes added. (`#53562 <https://github.com/llvm/llvm-project/issues/53562>`_) - Fixed a bug that prevented initialization of an ``_Atomic``-qualified pointer from a null pointer constant. +- Fixed a bug that prevented casting to an ``_Atomic``-qualified type. + (`#39596 <https://github.com/llvm/llvm-project/issues/39596>`_) C2x Feature Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 9fd9369c96418..cd71288476345 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -65,9 +65,13 @@ namespace { // If a pr-value initially has the type cv-T, where T is a // cv-unqualified non-class, non-array type, the type of the // expression is adjusted to T prior to any further analysis. + // C2x 6.5.4p6: + // Preceding an expression by a parenthesized type name converts the + // value of the expression to the unqualified, non-atomic version of + // the named type. if (!S.Context.getLangOpts().ObjC && !DestType->isRecordType() && !DestType->isArrayType()) { - DestType = DestType.getUnqualifiedType(); + DestType = DestType.getAtomicUnqualifiedType(); } if (const BuiltinType *placeholder = diff --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c index 5cb9df411044e..b77e9465b38b8 100644 --- a/clang/test/Sema/atomic-expr.c +++ b/clang/test/Sema/atomic-expr.c @@ -205,3 +205,14 @@ _Atomic(int *) aip3 = &ai; /* expected-warning {{incompatible pointer types init // Test the behavior when converting the null pointer constant to an atomic // function pointer. _Atomic(int (*)(char)) afp = (void *)0; + +void func_18(void) { + // Ensure we can cast to atomic scalar types. + data2 = (_Atomic int)0; + (void)(_Atomic(int *))0; + + // But that we correctly reject casts to atomic aggregate types. + struct S { int a; } s; + struct T { int a; }; + (void)(_Atomic struct T)s; // expected-error {{used type 'struct T' where arithmetic or pointer type is required}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits