-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[ItaniumMangle] Add substitutions for record types when mangling vtables #109970
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 Author: tcwzxx (tcwzxx) ChangesFix #108015 The mangleNameOrStandardSubstitution function does not add the RD type into the substitution, which causes the mangling of the <base type> to be incorrect. Full diff: https://github.com/llvm/llvm-project/pull/109970.diff 2 Files Affected:
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6e1da0c3192da..962e62ef86c0ca 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -7326,11 +7326,13 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD,
raw_ostream &Out) {
// <special-name> ::= TC <type> <offset number> _ <base type>
CXXNameMangler Mangler(*this, Out);
+ QualType RDType = getASTContext().getRecordType(RD);
+ QualType TypeType = getASTContext().getRecordType(Type);
Mangler.getStream() << "_ZTC";
- Mangler.mangleNameOrStandardSubstitution(RD);
+ Mangler.mangleType(RDType);
Mangler.getStream() << Offset;
Mangler.getStream() << '_';
- Mangler.mangleNameOrStandardSubstitution(Type);
+ Mangler.mangleType(TypeType);
}
void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp
index d0800af55c87e8..848b026028be76 100644
--- a/clang/test/CodeGenCXX/mangle.cpp
+++ b/clang/test/CodeGenCXX/mangle.cpp
@@ -11,6 +11,8 @@ struct Y { };
//CHECK: @pr5966_i = external global
//CHECK: @_ZL8pr5966_j = internal global
+//CHECK: @_ZTCN6test624InstE0_NS_1A4ImplINS1_4WrapEEE
+
// CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X
bool operator+(const Y&, X* (&xs)[100]) { return false; }
@@ -1214,3 +1216,25 @@ namespace test61 {
// CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE
template void f<X>(int, int);
}
+
+namespace test62 {
+namespace A {
+
+class VBase {
+ public:
+ virtual ~VBase() {};
+};
+
+struct Wrap {};
+
+template <typename T>
+class Impl : public virtual VBase {
+ public:
+};
+
+} // namespace A
+
+struct Inst : public A::Impl<A::Wrap> {};
+
+void Test() { Inst a; }
+}
|
…d Record to the substitution
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!
Can you also add a release note, mentioning the potential ABI breaking change?
Please wait 24h before merging in case the other reviewers want to chime in.
Do we need an ABI flag guarding against the change as well? |
Yeah, I think this change should respect |
Thanks for the review. I have added the ABI version 19 and the release notes. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
Some nits, otherwise LGTM as well.
//CHECK: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS1_4WrapEEE | ||
//CHECK-CLANG-19: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS0_4WrapEEE |
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.
Can you move these two checks directly above the corresponding codes? Thanks!
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.
The construction vtable is a global variable, so it cannot be moved above the corresponding code.
@@ -237,6 +237,11 @@ class LangOptionsBase { | |||
/// in the initializers of members of local classes. | |||
Ver18, | |||
|
|||
/// Attempt to be ABI-compatible with code generated by Clang 19.0.x. | |||
/// This causes clang to: | |||
/// - Incorrect Mangling of CXXCtorVTable |
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.
/// - Incorrect Mangling of CXXCtorVTable | |
/// - Incorrectly mangle CXX vtable substitutions in some cases... |
It would be great if you could flesh out the behavior changes here.
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. Updated.
Fix #108015
The mangleNameOrStandardSubstitution function does not add the RD type into the substitution, which causes the mangling of the <base type> to be incorrect.