Skip to content

[clang] Non-object types are non-trivially relocatable #69734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion clang/test/SemaCXX/type-traits-incomplete.cpp
Original file line number Diff line number Diff line change
@@ -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}}
}
16 changes: 16 additions & 0 deletions clang/test/SemaCXX/type-traits-nonobject.cpp
Original file line number Diff line number Diff line change
@@ -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()), "");