[PATCH] Mangling of member-expressions involving anonymous unions.

Richard Smith richard at metafoo.co.uk
Mon Oct 27 19:38:04 PDT 2014


If I reduce to a valid testcase (dropping one layer of the `union`), then EDG mangles your `x.implicit_this(y)` callee as:

  _ZNK5test61XIiE13implicit_thisINS_1YEEEDTclfp_L_ZNS1_4__C11mEEEET_

whereas GCC and Clang with this patch mangle it as

  _ZNK5test61XIiE13implicit_thisINS_1YEEEDTclfp_dtdefpT1mEET_

The difference is the argument to `f`; EDG uses

  L_ZNS1_4__C11mEE

which is <//external-name//> `test6::X<int>::__C1::m`, which doesn't seem very good. I think GCC's mangling is the best option here, but please also suggest this on the [cxx-abi-dev](http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev) mailing list.

================
Comment at: lib/AST/ItaniumMangle.cpp:2538
@@ +2537,3 @@
+    while (const auto *ME = dyn_cast<MemberExpr>(base)) {
+      if (ME->getMemberDecl()->getIdentifier())
+        break;
----------------
Please use

  if (isa<IndirectFieldDecl>(ME->getMemberDecl()))

... to more directly express the intent here.

================
Comment at: test/CodeGenCXX/mangle-exprs.cpp:225-226
@@ +224,4 @@
+
+    union {
+      union {
+        int m;
----------------
This is, strictly speaking, ill-formed; you cannot define a type within an anonymous union. Please also add a test case with only one layer of anonymous union so that we test the non-extension case. Please also add a test with an anonymous struct (maybe to this multi-layer case).

================
Comment at: test/CodeGenCXX/mangle-exprs.cpp:234-238
@@ +233,7 @@
+
+    template <class F>
+    auto explicit_this_arrow(F f) const -> decltype(f(this->m)) {}
+
+    template <class F>
+    auto explicit_this_dot(F f) const -> decltype(f((*this).m)) {}
+  };
----------------
These are both ill-formed. You can't use `this->` (or `(*this).`) in a trailing return type because the class type is not yet complete (but it appears we don't diagnose it in this case). Please use a type other than `X` in this check.

http://reviews.llvm.org/D5997






More information about the cfe-commits mailing list