-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Fix assertion failure in constexpr union deserialization #140179
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
Conversation
@llvm/pr-subscribers-clang-modules Author: Alexander Kornienko (alexfh) ChangesThis commit fixes #140130 Full diff: https://github.com/llvm/llvm-project/pull/140179.diff 2 Files Affected:
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 33336d57b6298..f3f0039ffe33e 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -414,7 +414,7 @@ let Class = PropertyTypeCase<APValue, "Union"> in {
let Read = [{ node.getUnionValue() }];
}
def : Creator<[{
- return APValue(cast<clang::FieldDecl>(fieldDecl), std::move(value));
+ return APValue(cast_if_present<clang::FieldDecl>(fieldDecl), std::move(value));
}]>;
}
let Class = PropertyTypeCase<APValue, "AddrLabelDiff"> in {
diff --git a/clang/test/Modules/pr140130.cpp b/clang/test/Modules/pr140130.cpp
new file mode 100644
index 0000000000000..da26a005b04f8
--- /dev/null
+++ b/clang/test/Modules/pr140130.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=c -xc++ c.cppmap -o c.pcm
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=a -fmodule-map-file=a.cppmap \
+// RUN: -fmodule-file=c.pcm -xc++ a.cppmap -o a.pcm
+
+//--- a.cppmap
+module "a" {
+ header "a.h"
+}
+//--- a.h
+#include "b.h"
+//--- b.h
+#ifndef _B_H_
+#define _B_H_
+struct B {
+ consteval B() {}
+ union {
+ int a;
+ };
+};
+constexpr B b;
+#endif
+//--- c.cppmap
+module "c" {
+header "c.h"
+}
+//--- c.h
+#include "b.h"
|
@llvm/pr-subscribers-clang Author: Alexander Kornienko (alexfh) ChangesThis commit fixes #140130 Full diff: https://github.com/llvm/llvm-project/pull/140179.diff 2 Files Affected:
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 33336d57b6298..f3f0039ffe33e 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -414,7 +414,7 @@ let Class = PropertyTypeCase<APValue, "Union"> in {
let Read = [{ node.getUnionValue() }];
}
def : Creator<[{
- return APValue(cast<clang::FieldDecl>(fieldDecl), std::move(value));
+ return APValue(cast_if_present<clang::FieldDecl>(fieldDecl), std::move(value));
}]>;
}
let Class = PropertyTypeCase<APValue, "AddrLabelDiff"> in {
diff --git a/clang/test/Modules/pr140130.cpp b/clang/test/Modules/pr140130.cpp
new file mode 100644
index 0000000000000..da26a005b04f8
--- /dev/null
+++ b/clang/test/Modules/pr140130.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=c -xc++ c.cppmap -o c.pcm
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=a -fmodule-map-file=a.cppmap \
+// RUN: -fmodule-file=c.pcm -xc++ a.cppmap -o a.pcm
+
+//--- a.cppmap
+module "a" {
+ header "a.h"
+}
+//--- a.h
+#include "b.h"
+//--- b.h
+#ifndef _B_H_
+#define _B_H_
+struct B {
+ consteval B() {}
+ union {
+ int a;
+ };
+};
+constexpr B b;
+#endif
+//--- c.cppmap
+module "c" {
+header "c.h"
+}
+//--- c.h
+#include "b.h"
|
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.
Thanks for the fix.
I think we need a release note in clang/docs/ReleaseNotes.rst
Agreed, this needs a release note |
Which aspect would you like to cover in the release notes? The fix of the mismatch between AST writer and AST reader or something else? Do you have a specific wording in mind? |
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
Something like:
- Fixes serialization of constexpr structs containing unions. (#GH140130)
Thanks for the suggestion, added to the release notes. |
This commit fixes #140130