https://github.com/AMP999 updated https://github.com/llvm/llvm-project/pull/77092
>From 5d8204ef66bea614d614b5c16a2ddf765402f710 Mon Sep 17 00:00:00 2001 From: Amirreza Ashouri <ar.ashouri...@gmail.com> Date: Wed, 3 Jan 2024 23:23:14 +0330 Subject: [PATCH] [clang] Fix behavior of __is_trivially_relocatable(volatile int) Consistent with `__is_trivially_copyable(volatile int) == true` and `__is_trivially_relocatable(volatile Trivial) == true`, `__is_trivially_relocatable(volatile int)` should also be `true`. Fixes https://github.com/llvm/llvm-project/issues/77091 [clang] [test] New tests for __is_trivially_relocatable(cv-qualified type) --- clang/docs/ReleaseNotes.rst | 9 ++++++--- clang/lib/AST/Type.cpp | 2 ++ clang/test/SemaCXX/type-traits.cpp | 31 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 37f8bbc89d8949..0fc10a77a73964 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -664,9 +664,6 @@ Bug Fixes in This Version - Fix crash during code generation of C++ coroutine initial suspend when the return type of await_resume is not trivially destructible. Fixes (`#63803 <https://github.com/llvm/llvm-project/issues/63803>`_) -- ``__is_trivially_relocatable`` no longer returns true for non-object types - such as references and functions. - Fixes (`#67498 <https://github.com/llvm/llvm-project/issues/67498>`_) - Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members which are not member functions. - Support UDLs in ``static_assert`` message. @@ -699,6 +696,12 @@ Bug Fixes in This Version - Clang now accepts recursive non-dependent calls to functions with deduced return type. Fixes (`#71015 <https://github.com/llvm/llvm-project/issues/71015>`_) +- ``__is_trivially_relocatable`` no longer returns ``true`` for non-object types + such as references and functions, and no longer returns ``false`` for volatile-qualified types. + Fixes (`#67498 <https://github.com/llvm/llvm-project/issues/67498>`_) and + (`#77091 <https://github.com/llvm/llvm-project/issues/77091>`_) + + - Fix assertion failure when initializing union containing struct with flexible array member using empty initializer list. Fixes (`#77085 <https://github.com/llvm/llvm-project/issues/77085>`_) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index b419fc8836b032..aa797de099b0c9 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2669,6 +2669,8 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const { return false; } else if (const auto *RD = BaseElementType->getAsRecordDecl()) { return RD->canPassInRegisters(); + } else if (BaseElementType.isTriviallyCopyableType(Context)) { + return true; } else { switch (isNonTrivialToPrimitiveDestructiveMove()) { case PCK_Trivial: diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp index c5d196a2590f8d..492f08142591a9 100644 --- a/clang/test/SemaCXX/type-traits.cpp +++ b/clang/test/SemaCXX/type-traits.cpp @@ -3092,6 +3092,8 @@ namespace is_trivially_relocatable { static_assert(!__is_trivially_relocatable(void), ""); static_assert(__is_trivially_relocatable(int), ""); static_assert(__is_trivially_relocatable(int[]), ""); +static_assert(__is_trivially_relocatable(const int), ""); +static_assert(__is_trivially_relocatable(volatile int), ""); enum Enum {}; static_assert(__is_trivially_relocatable(Enum), ""); @@ -3103,7 +3105,28 @@ static_assert(__is_trivially_relocatable(Union[]), ""); struct Trivial {}; static_assert(__is_trivially_relocatable(Trivial), ""); +static_assert(__is_trivially_relocatable(const Trivial), ""); +static_assert(__is_trivially_relocatable(volatile Trivial), ""); + static_assert(__is_trivially_relocatable(Trivial[]), ""); +static_assert(__is_trivially_relocatable(const Trivial[]), ""); +static_assert(__is_trivially_relocatable(volatile Trivial[]), ""); + +static_assert(__is_trivially_relocatable(int[10]), ""); +static_assert(__is_trivially_relocatable(const int[10]), ""); +static_assert(__is_trivially_relocatable(volatile int[10]), ""); + +static_assert(__is_trivially_relocatable(int[10][10]), ""); +static_assert(__is_trivially_relocatable(const int[10][10]), ""); +static_assert(__is_trivially_relocatable(volatile int[10][10]), ""); + +static_assert(__is_trivially_relocatable(int[]), ""); +static_assert(__is_trivially_relocatable(const int[]), ""); +static_assert(__is_trivially_relocatable(volatile int[]), ""); + +static_assert(__is_trivially_relocatable(int[][10]), ""); +static_assert(__is_trivially_relocatable(const int[][10]), ""); +static_assert(__is_trivially_relocatable(volatile int[][10]), ""); struct Incomplete; // expected-note {{forward declaration of 'is_trivially_relocatable::Incomplete'}} bool unused = __is_trivially_relocatable(Incomplete); // expected-error {{incomplete type}} @@ -3113,6 +3136,8 @@ struct NontrivialDtor { }; static_assert(!__is_trivially_relocatable(NontrivialDtor), ""); static_assert(!__is_trivially_relocatable(NontrivialDtor[]), ""); +static_assert(!__is_trivially_relocatable(const NontrivialDtor), ""); +static_assert(!__is_trivially_relocatable(volatile NontrivialDtor), ""); struct NontrivialCopyCtor { NontrivialCopyCtor(const NontrivialCopyCtor&) {} @@ -3131,12 +3156,16 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor { }; static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor), ""); static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[]), ""); +static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor), ""); +static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialDtor), ""); struct [[clang::trivial_abi]] TrivialAbiNontrivialCopyCtor { TrivialAbiNontrivialCopyCtor(const TrivialAbiNontrivialCopyCtor&) {} }; static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor), ""); static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor[]), ""); +static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialCopyCtor), ""); +static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialCopyCtor), ""); // A more complete set of tests for the behavior of trivial_abi can be found in // clang/test/SemaCXX/attr-trivial-abi.cpp @@ -3145,6 +3174,8 @@ struct [[clang::trivial_abi]] TrivialAbiNontrivialMoveCtor { }; static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor), ""); static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor[]), ""); +static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialMoveCtor), ""); +static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialMoveCtor), ""); } // namespace is_trivially_relocatable _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits