-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) #133077
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
5139570
to
686a9a7
Compare
@llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: Paul Schwabauer (koplas) ChangesWhen getting the TODO: Reduce test. Full diff: https://github.com/llvm/llvm-project/pull/133077.diff 2 Files Affected:
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index dbd02ef7f8011..7728669b3bcec 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2601,10 +2601,11 @@ class CXXConstructorDecl final
void anchor() override;
size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
- return CXXConstructorDeclBits.IsInheritingConstructor;
+ return getCanonicalDecl()->CXXConstructorDeclBits.IsInheritingConstructor;
}
size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
- return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
+ return getCanonicalDecl()
+ ->CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
}
ExplicitSpecifier getExplicitSpecifierInternal() const {
diff --git a/clang/test/Modules/ComplexExplicitSpecifier.cpp b/clang/test/Modules/ComplexExplicitSpecifier.cpp
new file mode 100644
index 0000000000000..33501ba264cc6
--- /dev/null
+++ b/clang/test/Modules/ComplexExplicitSpecifier.cpp
@@ -0,0 +1,45 @@
+// Tests complex explicit constructor across modules.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Foo.cppm \
+// RUN: -o %t/Foo.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface \
+// RUN: -fmodule-file=Foo=%t/Foo.pcm \
+// RUN: %t/Bar.cppm \
+// RUN: -o %t/Bar.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj \
+// RUN: -main-file-name Bar.cppm \
+// RUN: -fmodule-file=Foo=%t/Foo.pcm \
+// RUN: -x pcm %t/Bar.pcm \
+// RUN: -o %t/Bar.o
+
+//--- Foo.cppm
+export module Foo;
+
+export {
+template<class T>
+class Foo {
+ public:
+ template<class... Args>
+ explicit (sizeof...(Args) == 1) Foo(Args&&... args);
+};
+}
+
+template<class T>
+template<class... Args>
+inline Foo<T>::Foo(Args&&... args) {}
+
+//--- Bar.cppm
+export module Bar;
+import Foo;
+
+struct Bar {};
+
+void a() {
+ auto foo = Foo<Bar>{};
+}
|
Thanks for working on this This change needs a release note. |
…efs llvm#132794) When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of its canonical declarations is returned. To correctly write the declaration record the ExplicitSpecifier of the current declaration must be used. Failing to do so results in a crash during deserialization.
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, Thanks!
Will you need me to merge that for you?
Yes, I don't have any permissions to merge this. |
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
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.
I am probably missing something here but I see you switched to using getExplicitSpecifierInternal()
but in your summary you talk about using the correct AllocKind but I just don't see how they related at all.
I see the line before does Record.push_back(D->getTrailingAllocKind());
. I looked at ExplicitSpecifier
and also don't see how it relates.
Could you please clarify?
CXXConstructorDecl
refs #132794
When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of its canonical declarations is returned. To correctly write the declaration record the ExplicitSpecifier of the current declaration must be used.
Failing to do so results in a crash during deserialization.