Hi rsmith,

When mangling member-expressions, mangle only access to first named member,
ignoring unnamed ones in anonymous unions. This fixes crash reported in bug
report 15542, and results in behaviour consistent with GCC.

http://reviews.llvm.org/D5997

Files:
  lib/AST/ItaniumMangle.cpp
  test/CodeGenCXX/mangle-exprs.cpp
Index: lib/AST/ItaniumMangle.cpp
===================================================================
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -2532,6 +2532,15 @@
   // <expression> ::= dt <expression> <unresolved-name>
   //              ::= pt <expression> <unresolved-name>
   if (base) {
+
+    // Ignore member expressions involving anonymous unions.
+    while (const auto *ME = dyn_cast<MemberExpr>(base)) {
+      if (ME->getMemberDecl()->getIdentifier())
+        break;
+      base = ME->getBase();
+      isArrow = ME->isArrow();
+    }
+
     if (base->isImplicitCXXThis()) {
       // Note: GCC mangles member expressions to the implicit 'this' as
       // *this., whereas we represent them as this->. The Itanium C++ ABI
Index: test/CodeGenCXX/mangle-exprs.cpp
===================================================================
--- test/CodeGenCXX/mangle-exprs.cpp
+++ test/CodeGenCXX/mangle-exprs.cpp
@@ -217,3 +217,41 @@
   template void a<int>(decltype(noexcept(int())));
   // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE(
 }
+
+namespace test6 {
+  template <typename T>
+  struct X {
+
+    union {
+      union {
+        int m;
+      };
+    };
+
+    template <class F>
+    auto implicit_this(F f) const -> decltype(f(m)) {}
+
+    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)) {}
+  };
+
+  struct Y { void operator()(int); };
+
+  void instantiate() {
+    X<int> x;
+    Y y;
+
+    // CHECK: call void @_ZNK5test61XIiE13implicit_thisINS_1YEEEDTclfp_dtdefpT1mEET_(
+    x.implicit_this(y);
+
+    // CHECK: call void @_ZNK5test61XIiE19explicit_this_arrowINS_1YEEEDTclfp_ptfpT1mEET_(
+    x.explicit_this_arrow(y);
+
+    // CHECK: call void @_ZNK5test61XIiE17explicit_this_dotINS_1YEEEDTclfp_dtdefpT1mEET_(
+    x.explicit_this_dot(y);
+  }
+}
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to