I have updated tests to include an anonymous union, an anonymous struct and
combinations of those two. In addition, dependency on non-diagnosed incomplete
type in member-expression has been removed.

End condition is now made more explicit using IndirectFieldDecl, but this
requires additional check ensuring that we are in fact dealing with an
anonymous union / struct (so that we don't break non-anonymous case). Did you
have something simpler in mind here?

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,19 @@
   // <expression> ::= dt <expression> <unresolved-name>
   //              ::= pt <expression> <unresolved-name>
   if (base) {
+
+    // Ignore member expressions involving anonymous unions.
+    if (const auto *RT = base->getType()->getAs<RecordType>()) {
+      if (RT->getDecl()->isAnonymousStructOrUnion()) {
+        while (const auto *ME = dyn_cast<MemberExpr>(base)) {
+          if (isa<IndirectFieldDecl>(ME->getMemberDecl()))
+            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,62 @@
   template void a<int>(decltype(noexcept(int())));
   // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE(
 }
+
+namespace test6 {
+  struct X {
+    int i;
+  };
+
+  struct Y {
+    union {
+      X u;
+    };
+
+    struct {
+      X s;
+    };
+
+    union {
+      union {
+        struct {
+          struct {
+            X uuss;
+          };
+        };
+      };
+    };
+  };
+
+  Y y, *yp;
+
+  template<typename T>
+  void f1(decltype(T(y.u.i))) {}
+  template void f1<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f1IiEEvDTcvT_dtdtL_ZNS_1yEE1u1iE
+
+  template<typename T>
+  void f2(decltype(T(y.s.i))) {}
+  template void f2<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f2IiEEvDTcvT_dtdtL_ZNS_1yEE1s1iE
+
+  template<typename T>
+  void f3(decltype(T(y.uuss.i))) {}
+  template void f3<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f3IiEEvDTcvT_dtdtL_ZNS_1yEE4uuss1iE
+
+  template<typename T>
+  void f4(decltype(T(yp->u.i))) {}
+  template void f4<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f4IiEEvDTcvT_dtptL_ZNS_2ypEE1u1iE
+
+  template<typename T>
+  void f5(decltype(T(yp->s.i))) {}
+  template void f5<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f5IiEEvDTcvT_dtptL_ZNS_2ypEE1s1iE
+
+  template<typename T>
+  void f6(decltype(T(yp->uuss.i))) {}
+  template void f6<int>(int);
+  // CHECK-LABEL: define weak_odr void @_ZN5test62f6IiEEvDTcvT_dtptL_ZNS_2ypEE4uuss1iE
+}
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to