llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[ABI] mangleCXXCtorVTable mangles an incorrect name

Open tcwzxx opened this issue 2 years ago • 2 comments


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

The code above will generate a CtorVTable with the name _ZTC4Inst0_N1A4ImplINS_4WrapEEE. After demangling, the result is construction vtable for A::Impl<Inst::Wrap>-in-Inst. However, Inst::Wrap is incorrect.

https://github.com/llvm/llvm-project/blob/b0ffaa79050460d724eec1b12363c439b43d5ae5/clang/lib/AST/ItaniumMangle.cpp#L7327-L7338

Because mangleNameOrStandardSubstitution never adds RD as a substitution.

tcwzxx avatar Sep 10 '24 12:09 tcwzxx

@llvm/issue-subscribers-clang-frontend

Author: tcwzxx (tcwzxx)

```C++

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

The code above will generate a `CtorVTable` with the name `_ZTC4Inst0_N1A4ImplINS_4WrapEEE`. After demangling, the result is `construction vtable for A::Impl&lt;Inst::Wrap&gt;-in-Inst`. However, `Inst::Wrap` is incorrect.

https://github.com/llvm/llvm-project/blob/b0ffaa79050460d724eec1b12363c439b43d5ae5/clang/lib/AST/ItaniumMangle.cpp#L7327-L7338

 because `mangleNameOrStandardSubstitution` never adds `RD` as a substitution




</details>

llvmbot avatar Sep 10 '24 12:09 llvmbot

For CXXCtorVTable

<special-name> ::= TC <type> <offset number> _ <base type>

I think we should use mangleType instead of mangleNameOrStandardSubstitution.

tcwzxx avatar Sep 10 '24 13:09 tcwzxx