Author: Amirreza Ashouri Date: 2023-11-28T19:44:38+01:00 New Revision: 98e674c9f16d677d95c67bc130e267fae331e43c
URL: https://github.com/llvm/llvm-project/commit/98e674c9f16d677d95c67bc130e267fae331e43c DIFF: https://github.com/llvm/llvm-project/commit/98e674c9f16d677d95c67bc130e267fae331e43c.diff LOG: [clang] Non-object types are non-trivially relocatable (#69734) Both active C++ proposals (P1144 and P2786) agree that `is_trivially_relocatable_v<int&>` and `is_trivially_relocatable_v<int()>` should be false, not true. Only complete object types can be trivially relocatable. Fixes #67498 Added: clang/test/SemaCXX/type-traits-nonobject.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/Type.cpp clang/test/SemaCXX/type-traits-incomplete.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e2e8ee8d76d2e10..e4beeee0a2cb5e0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -637,6 +637,9 @@ 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. diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index c8e452e2feab0bf..160a725939ccd4c 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const { if (BaseElementType->isIncompleteType()) { return false; + } else if (!BaseElementType->isObjectType()) { + return false; } else if (const auto *RD = BaseElementType->getAsRecordDecl()) { return RD->canPassInRegisters(); } else { diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp b/clang/test/SemaCXX/type-traits-incomplete.cpp index c0a520e167698af..3e341d648244075 100644 --- a/clang/test/SemaCXX/type-traits-incomplete.cpp +++ b/clang/test/SemaCXX/type-traits-incomplete.cpp @@ -1,8 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -struct S; // expected-note 2 {{forward declaration of 'S'}} +struct S; // expected-note 6 {{forward declaration of 'S'}} void f() { __is_pod(S); // expected-error{{incomplete type 'S' used in type trait expression}} __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait expression}} + + __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in type trait expression}} + __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}} + + __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used in type trait expression}} + __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}} } diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp b/clang/test/SemaCXX/type-traits-nonobject.cpp new file mode 100644 index 000000000000000..c9e3c30e5533d48 --- /dev/null +++ b/clang/test/SemaCXX/type-traits-nonobject.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +// expected-no-diagnostics + +static_assert(!__is_pod(void), ""); +static_assert(!__is_pod(int&), ""); +static_assert(!__is_pod(int()), ""); + +static_assert(!__is_trivially_copyable(void), ""); +static_assert(!__is_trivially_copyable(int&), ""); +static_assert(!__is_trivially_copyable(int()), ""); + +static_assert(!__is_trivially_relocatable(void), ""); +static_assert(!__is_trivially_relocatable(int&), ""); +static_assert(!__is_trivially_relocatable(int()), ""); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits