-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Implement CWG1719 "Layout compatibility and cv-qualification revisited" #82358
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…revisited" This patch updates our internal notion of layout-compatible, which in turn fixes `__is_layout_compatible` intrinsic.
@llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) ChangesThis patch updates our internal notion of Full diff: https://github.com/llvm/llvm-project/pull/82358.diff 5 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ea4a9a5a4256c..ffdc2a2629e6e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,9 +98,8 @@ C++20 Feature Support
- Implemented the `__is_layout_compatible` intrinsic to support
`P0466R5: Layout-compatibility and Pointer-interconvertibility Traits <https://wg21.link/P0466R5>`_.
- Note: `CWG1719: Layout compatibility and cv-qualification revisited <https://cplusplus.github.io/CWG/issues/1719.html>`_
- and `CWG2759: [[no_unique_address] and common initial sequence <https://cplusplus.github.io/CWG/issues/2759.html>`_
- are not yet implemented.
+ Note: `CWG2759: [[no_unique_address] and common initial sequence <https://cplusplus.github.io/CWG/issues/2759.html>`_
+ is not yet implemented.
C++23 Feature Support
^^^^^^^^^^^^^^^^^^^^^
@@ -120,6 +119,10 @@ Resolutions to C++ Defect Reports
in the template parameters, but is deduced from a previous argument.
(`#78449: <https://github.com/llvm/llvm-project/issues/78449>`_).
+- ``const`` and ``volatile`` qualifiers are now ignored when evaluating
+ layout compatibility of two types.
+ (`CWG1719: Layout compatibility and cv-qualification revisited <https://cplusplus.github.io/CWG/issues/1719.html>`_).
+
C Language Changes
------------------
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d951c0fc2732d2..e8bfb215a5b4c5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19124,15 +19124,16 @@ static bool isLayoutCompatible(ASTContext &C, QualType T1, QualType T2) {
if (T1.isNull() || T2.isNull())
return false;
- // C++11 [basic.types] p11:
- // If two types T1 and T2 are the same type, then T1 and T2 are
- // layout-compatible types.
- if (C.hasSameType(T1, T2))
- return true;
-
+ // C++20 [basic.types] p11:
+ // Two types cv1 T1 and cv2 T2 are layout-compatible types
+ // if T1 and T2 are the same type, layout-compatible enumerations (9.7.1),
+ // or layout-compatible standard-layout class types (11.4).
T1 = T1.getCanonicalType().getUnqualifiedType();
T2 = T2.getCanonicalType().getUnqualifiedType();
+ if (C.hasSameType(T1, T2))
+ return true;
+
const Type::TypeClass TC1 = T1->getTypeClass();
const Type::TypeClass TC2 = T2->getTypeClass();
diff --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index e5cee19337ebd4..d933c244aada42 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -46,7 +46,7 @@ namespace dr1715 { // dr1715: 3.9
#endif
}
-namespace dr1719 { // dr1719: no
+namespace dr1719 { // dr1719: 19
#if __cplusplus >= 201103L
struct CStruct {
int one;
@@ -66,11 +66,10 @@ struct CStructWithQualifiers {
static_assert(__is_layout_compatible(CStruct, const CStruct2), "");
static_assert(__is_layout_compatible(CStruct, volatile CStruct2), "");
static_assert(__is_layout_compatible(const CStruct, volatile CStruct2), "");
-// FIXME: all of the following pairs of types are layout-compatible
-static_assert(!__is_layout_compatible(int, const int), "");
-static_assert(!__is_layout_compatible(int, volatile int), "");
-static_assert(!__is_layout_compatible(const int, volatile int), "");
-static_assert(!__is_layout_compatible(CStruct, CStructWithQualifiers), "");
+static_assert(__is_layout_compatible(int, const int), "");
+static_assert(__is_layout_compatible(int, volatile int), "");
+static_assert(__is_layout_compatible(const int, volatile int), "");
+static_assert(__is_layout_compatible(CStruct, CStructWithQualifiers), "");
#endif
} // namespace dr1719
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index 6ff04b6c8c7223..94889d654abeca 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1711,13 +1711,13 @@ void is_layout_compatible(int n)
{
static_assert(__is_layout_compatible(void, void), "");
static_assert(!__is_layout_compatible(void, int), "");
- static_assert(!__is_layout_compatible(void, const void), ""); // FIXME: this is CWG1719
- static_assert(!__is_layout_compatible(void, volatile void), ""); // FIXME: this is CWG1719
- static_assert(!__is_layout_compatible(const int, volatile int), ""); // FIXME: this is CWG1719
+ static_assert(__is_layout_compatible(void, const void), "");
+ static_assert(__is_layout_compatible(void, volatile void), "");
+ static_assert(__is_layout_compatible(const int, volatile int), "");
static_assert(__is_layout_compatible(int, int), "");
- static_assert(!__is_layout_compatible(int, const int), ""); // FIXME: this is CWG1719
- static_assert(!__is_layout_compatible(int, volatile int), ""); // FIXME: this is CWG1719
- static_assert(!__is_layout_compatible(const int, volatile int), ""); // FIXME: this is CWG1719
+ static_assert(__is_layout_compatible(int, const int), "");
+ static_assert(__is_layout_compatible(int, volatile int), "");
+ static_assert(__is_layout_compatible(const int, volatile int), "");
static_assert(!__is_layout_compatible(int, unsigned int), "");
static_assert(!__is_layout_compatible(char, unsigned char), "");
static_assert(!__is_layout_compatible(char, signed char), "");
@@ -1758,7 +1758,7 @@ void is_layout_compatible(int n)
static_assert(!__is_layout_compatible(CppStructNonStandardByVirtBase, CppStructNonStandardByVirtBase2), "");
static_assert(!__is_layout_compatible(CppStructNonStandardBySameBase, CppStructNonStandardBySameBase2), "");
static_assert(!__is_layout_compatible(CppStructNonStandardBy2ndVirtBase, CppStructNonStandardBy2ndVirtBase2), "");
- static_assert(!__is_layout_compatible(CStruct, CStructWithQualifiers), ""); // FIXME: this is CWG1719
+ static_assert(__is_layout_compatible(CStruct, CStructWithQualifiers), "");
static_assert(__is_layout_compatible(CStruct, CStructNoUniqueAddress) == bool(__has_cpp_attribute(no_unique_address)), ""); // FIXME: this is CWG2759
static_assert(__is_layout_compatible(CStructNoUniqueAddress, CStructNoUniqueAddress2) == bool(__has_cpp_attribute(no_unique_address)), ""); // FIXME: this is CWG2759
static_assert(__is_layout_compatible(CStruct, CStructAlignment), "");
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index e9b18b1e283e66..38e2cb63142662 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7812,7 +7812,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1334.html">1334</a></td>
<td>NAD</td>
<td>Layout compatibility and cv-qualification</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="unreleased" align="center">Superseded by <a href="#1719">1719</a></td>
</tr>
<tr id="1335">
<td><a href="https://cplusplus.github.io/CWG/issues/1335.html">1335</a></td>
@@ -10122,7 +10122,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1719.html">1719</a></td>
<td>CD4</td>
<td>Layout compatibility and cv-qualification revisited</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="unreleased" align="center">Clang 19</td>
</tr>
<tr id="1720">
<td><a href="https://cplusplus.github.io/CWG/issues/1720.html">1720</a></td>
|
cor3ntin
approved these changes
Feb 21, 2024
AaronBallman
approved these changes
Feb 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
qiaojbao
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Mar 21, 2024
…9a3027d34 Local branch amd-gfx e849a30 Merged main:6d160a49c2e7f36367de3f61f0460e28921450d5 into amd-gfx:71200611d382 Remote branch main 7318585 [clang] Implement CWG1719 "Layout compatibility and cv-qualification revisited" (llvm#82358)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
c++
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch updates our internal notion of
layout-compatible
, which in turn fixes__is_layout_compatible
intrinsic.