[clang] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 25 05:31:36 PDT 2024


https://github.com/tcwzxx created https://github.com/llvm/llvm-project/pull/109970

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.

>From cb60af05cd01da679a473538e80dfb22feefc4bb Mon Sep 17 00:00:00 2001
From: tcwzxx <tcwzxx at gmail.com>
Date: Wed, 25 Sep 2024 19:19:08 +0800
Subject: [PATCH] In the mangleCXXCtorVTable function, the mangleType function
 never adds RD into the substitution, which causes a substitution index error

---
 clang/lib/AST/ItaniumMangle.cpp  |  6 ++++--
 clang/test/CodeGenCXX/mangle.cpp | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

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; }
+}



More information about the cfe-commits mailing list