$OpenBSD: patch-tools_clang_lib_CodeGen_CGExpr_cpp,v 1.1 2018/04/07 14:55:42 ajacoutot Exp $

[CodeGen] Fix TBAA info for accesses to members of base classes

Resolves:
Bug 35724 - regression (r315984): fatal error: error in backend:
Broken function found (Did not see access type in access path!)

Index: tools/clang/lib/CodeGen/CGExpr.cpp
--- tools/clang/lib/CodeGen/CGExpr.cpp.orig
+++ tools/clang/lib/CodeGen/CGExpr.cpp
@@ -1034,8 +1034,12 @@ Address CodeGenFunction::EmitPointerWithAlignment(cons
     // Derived-to-base conversions.
     case CK_UncheckedDerivedToBase:
     case CK_DerivedToBase: {
-      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
-                                              TBAAInfo);
+      // TODO: Support accesses to members of base classes in TBAA. For now, we
+      // conservatively pretend that the complete object is of the base class
+      // type.
+      if (TBAAInfo)
+        *TBAAInfo = CGM.getTBAAAccessInfo(E->getType());
+      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
       auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
       return GetAddressOfBaseClass(Addr, Derived,
                                    CE->path_begin(), CE->path_end(),
