kosarev updated this revision to Diff 119373.
kosarev edited the summary of this revision.
kosarev added a comment.

Rebased on top of https://reviews.llvm.org/D39008 and ready for review.


https://reviews.llvm.org/D38126

Files:
  CodeGen/CGAtomic.cpp
  CodeGen/CGClass.cpp
  CodeGen/CGExpr.cpp
  CodeGen/CGObjCRuntime.cpp
  CodeGen/CGOpenMPRuntime.cpp
  CodeGen/CGValue.h
  CodeGen/CodeGenFunction.cpp
  CodeGen/CodeGenFunction.h

Index: CodeGen/CodeGenFunction.h
===================================================================
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1919,45 +1919,39 @@
 
   LValue MakeAddrLValue(Address Addr, QualType T,
                         AlignmentSource Source = AlignmentSource::Type) {
-    return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
-                            CGM.getTBAAAccessInfo(T));
+    return LValue::MakeAddr(Addr, T, getContext(),
+                            LValueBaseInfo(Source, CGM.getTBAAAccessInfo(T)));
   }
 
-  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo,
-                        TBAAAccessInfo TBAAInfo) {
-    return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
+  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo) {
+    return LValue::MakeAddr(Addr, T, getContext(), BaseInfo);
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
                         AlignmentSource Source = AlignmentSource::Type) {
     return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-                            LValueBaseInfo(Source), CGM.getTBAAAccessInfo(T));
+                            LValueBaseInfo(Source, CGM.getTBAAAccessInfo(T)));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-                        LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
-    return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-                            BaseInfo, TBAAInfo);
+                        LValueBaseInfo BaseInfo) {
+    return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo);
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   CharUnits getNaturalTypeAlignment(QualType T,
                                     LValueBaseInfo *BaseInfo = nullptr,
-                                    TBAAAccessInfo *TBAAInfo = nullptr,
                                     bool forPointeeType = false);
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
-                                           LValueBaseInfo *BaseInfo = nullptr,
-                                           TBAAAccessInfo *TBAAInfo = nullptr);
+                                           LValueBaseInfo *BaseInfo = nullptr);
 
   Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-                              LValueBaseInfo *BaseInfo = nullptr,
-                              TBAAAccessInfo *TBAAInfo = nullptr);
+                              LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
-                            LValueBaseInfo *BaseInfo = nullptr,
-                            TBAAAccessInfo *TBAAInfo = nullptr);
+                            LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
   /// CreateTempAlloca - This creates an alloca and inserts it into the entry
@@ -3083,13 +3077,13 @@
                                 SourceLocation Loc,
                                 AlignmentSource Source = AlignmentSource::Type,
                                 bool isNontemporal = false) {
-    return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source),
-                            CGM.getTBAAAccessInfo(Ty), isNontemporal);
+    return EmitLoadOfScalar(Addr, Volatile, Ty, Loc,
+                            LValueBaseInfo(Source, CGM.getTBAAAccessInfo(Ty)),
+                            isNontemporal);
   }
 
   llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
                                 SourceLocation Loc, LValueBaseInfo BaseInfo,
-                                TBAAAccessInfo TBAAInfo,
                                 bool isNontemporal = false);
 
   /// EmitLoadOfScalar - Load a scalar value from an address, taking
@@ -3105,13 +3099,13 @@
                          bool Volatile, QualType Ty,
                          AlignmentSource Source = AlignmentSource::Type,
                          bool isInit = false, bool isNontemporal = false) {
-    EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source),
-                      CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
+    EmitStoreOfScalar(Value, Addr, Volatile, Ty,
+                      LValueBaseInfo(Source, CGM.getTBAAAccessInfo(Ty)),
+                      isInit, isNontemporal);
   }
 
   void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
-                         bool Volatile, QualType Ty,
-                         LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo,
+                         bool Volatile, QualType Ty, LValueBaseInfo BaseInfo,
                          bool isInit = false, bool isNontemporal = false);
 
   /// EmitStoreOfScalar - Store a scalar value to an address, taking
@@ -3182,8 +3176,7 @@
   RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);
 
   Address EmitArrayToPointerDecay(const Expr *Array,
-                                  LValueBaseInfo *BaseInfo = nullptr,
-                                  TBAAAccessInfo *TBAAInfo = nullptr);
+                                  LValueBaseInfo *BaseInfo = nullptr);
 
   class ConstantEmission {
     llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference;
@@ -3325,8 +3318,7 @@
   Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
                                           llvm::Value *memberPtr,
                                           const MemberPointerType *memberPtrType,
-                                          LValueBaseInfo *BaseInfo = nullptr,
-                                          TBAAAccessInfo *TBAAInfo = nullptr);
+                                          LValueBaseInfo *BaseInfo = nullptr);
   RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
                                       ReturnValueSlot ReturnValue);
 
@@ -3905,8 +3897,7 @@
   /// reasonable to just ignore the returned alignment when it isn't from an
   /// explicit source.
   Address EmitPointerWithAlignment(const Expr *Addr,
-                                   LValueBaseInfo *BaseInfo = nullptr,
-                                   TBAAAccessInfo *TBAAInfo = nullptr);
+                                   LValueBaseInfo *BaseInfo = nullptr);
 
   void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
 
Index: CodeGen/CodeGenFunction.cpp
===================================================================
--- CodeGen/CodeGenFunction.cpp
+++ CodeGen/CodeGenFunction.cpp
@@ -118,32 +118,28 @@
 }
 
 CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,
-                                                    LValueBaseInfo *BaseInfo,
-                                                    TBAAAccessInfo *TBAAInfo) {
-  return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo, TBAAInfo,
+                                                    LValueBaseInfo *BaseInfo) {
+  return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo,
                                  /* forPointeeType= */ true);
 }
 
 CharUnits CodeGenFunction::getNaturalTypeAlignment(QualType T,
                                                    LValueBaseInfo *BaseInfo,
-                                                   TBAAAccessInfo *TBAAInfo,
                                                    bool forPointeeType) {
-  if (TBAAInfo)
-    *TBAAInfo = CGM.getTBAAAccessInfo(T);
-
   // Honor alignment typedef attributes even on incomplete types.
   // We also honor them straight for C++ class types, even as pointees;
   // there's an expressivity gap here.
   if (auto TT = T->getAs<TypedefType>()) {
     if (auto Align = TT->getDecl()->getMaxAlignment()) {
       if (BaseInfo)
-        *BaseInfo = LValueBaseInfo(AlignmentSource::AttributedType);
+        *BaseInfo = LValueBaseInfo(AlignmentSource::AttributedType,
+                                   CGM.getTBAAAccessInfo(T));
       return getContext().toCharUnitsFromBits(Align);
     }
   }
 
   if (BaseInfo)
-    *BaseInfo = LValueBaseInfo(AlignmentSource::Type);
+    *BaseInfo = LValueBaseInfo(AlignmentSource::Type, CGM.getTBAAAccessInfo(T));
 
   CharUnits Alignment;
   if (T->isIncompleteType()) {
@@ -174,21 +170,18 @@
 
 LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
-  CharUnits Alignment = getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo);
-  return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo,
-                          TBAAInfo);
+  CharUnits Alignment = getNaturalTypeAlignment(T, &BaseInfo);
+  return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo);
 }
 
 /// Given a value of type T* that may not be to a complete object,
 /// construct an l-value with the natural pointee alignment of T.
 LValue
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
-  CharUnits Align = getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo,
+  CharUnits Align = getNaturalTypeAlignment(T, &BaseInfo,
                                             /* forPointeeType= */ true);
-  return MakeAddrLValue(Address(V, Align), T, BaseInfo, TBAAInfo);
+  return MakeAddrLValue(Address(V, Align), T, BaseInfo);
 }
 
 
Index: CodeGen/CGValue.h
===================================================================
--- CodeGen/CGValue.h
+++ CodeGen/CGValue.h
@@ -31,6 +31,7 @@
 namespace CodeGen {
   class AggValueSlot;
   struct CGBitFieldInfo;
+  class CodeGenModule;
 
 /// RValue - This trivial value class is used to represent the result of an
 /// expression that is evaluated.  It can be one of three things: either a
@@ -149,16 +150,18 @@
 
 class LValueBaseInfo {
   AlignmentSource AlignSource;
+  TBAAAccessInfo TBAAInfo;
 
 public:
-  explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type)
-    : AlignSource(Source) {}
+  explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type,
+                          TBAAAccessInfo TBAAInfo = TBAAAccessInfo())
+    : AlignSource(Source), TBAAInfo(TBAAInfo) {}
   AlignmentSource getAlignmentSource() const { return AlignSource; }
   void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; }
+  TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
+  void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
 
-  void mergeForCast(const LValueBaseInfo &Info) {
-    setAlignmentSource(Info.getAlignmentSource());
-  }
+  void mergeForCast(const LValueBaseInfo &Info, CodeGenModule &CGM);
 };
 
 /// LValue - This represents an lvalue references.  Because C/C++ allow
@@ -216,7 +219,6 @@
   bool ImpreciseLifetime : 1;
 
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
 
   // This flag shows if a nontemporal load/stores should be used when accessing
   // this lvalue.
@@ -226,16 +228,15 @@
 
 private:
   void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment,
-                  LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
+                  LValueBaseInfo BaseInfo) {
     assert((!Alignment.isZero() || Type->isIncompleteType()) &&
            "initializing l-value with zero alignment!");
     this->Type = Type;
     this->Quals = Quals;
     this->Alignment = Alignment.getQuantity();
     assert(this->Alignment == Alignment.getQuantity() &&
            "Alignment exceeds allowed max!");
     this->BaseInfo = BaseInfo;
-    this->TBAAInfo = TBAAInfo;
 
     // Initialize Objective-C flags.
     this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
@@ -302,8 +303,8 @@
   Expr *getBaseIvarExp() const { return BaseIvarExp; }
   void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
 
-  TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
-  void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
+  TBAAAccessInfo getTBAAInfo() const { return BaseInfo.getTBAAInfo(); }
+  void setTBAAInfo(TBAAAccessInfo Info) { BaseInfo.setTBAAInfo(Info); }
 
   const Qualifiers &getQuals() const { return Quals; }
   Qualifiers &getQuals() { return Quals; }
@@ -316,6 +317,10 @@
   LValueBaseInfo getBaseInfo() const { return BaseInfo; }
   void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
 
+  AlignmentSource getAlignmentSource() const {
+    return BaseInfo.getAlignmentSource();
+  }
+
   // simple lvalue
   llvm::Value *getPointer() const {
     assert(isSimple());
@@ -362,39 +367,37 @@
   llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; }
 
   static LValue MakeAddr(Address address, QualType type, ASTContext &Context,
-                         LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
+                         LValueBaseInfo BaseInfo) {
     Qualifiers qs = type.getQualifiers();
     qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
 
     LValue R;
     R.LVType = Simple;
     assert(address.getPointer()->getType()->isPointerTy());
     R.V = address.getPointer();
-    R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
+    R.Initialize(type, qs, address.getAlignment(), BaseInfo);
     return R;
   }
 
   static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx,
-                              QualType type, LValueBaseInfo BaseInfo,
-                              TBAAAccessInfo TBAAInfo) {
+                              QualType type, LValueBaseInfo BaseInfo) {
     LValue R;
     R.LVType = VectorElt;
     R.V = vecAddress.getPointer();
     R.VectorIdx = Idx;
     R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
-                 BaseInfo, TBAAInfo);
+                 BaseInfo);
     return R;
   }
 
   static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts,
-                                 QualType type, LValueBaseInfo BaseInfo,
-                                 TBAAAccessInfo TBAAInfo) {
+                                 QualType type, LValueBaseInfo BaseInfo) {
     LValue R;
     R.LVType = ExtVectorElt;
     R.V = vecAddress.getPointer();
     R.VectorElts = Elts;
     R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
-                 BaseInfo, TBAAInfo);
+                 BaseInfo);
     return R;
   }
 
@@ -405,23 +408,21 @@
   /// \param Info - The information describing how to perform the bit-field
   /// access.
   static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info,
-                             QualType type, LValueBaseInfo BaseInfo,
-                             TBAAAccessInfo TBAAInfo) {
+                             QualType type, LValueBaseInfo BaseInfo) {
     LValue R;
     R.LVType = BitField;
     R.V = Addr.getPointer();
     R.BitFieldInfo = &Info;
-    R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
-                 TBAAInfo);
+    R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo);
     return R;
   }
 
   static LValue MakeGlobalReg(Address Reg, QualType type) {
     LValue R;
     R.LVType = GlobalReg;
     R.V = Reg.getPointer();
     R.Initialize(type, type.getQualifiers(), Reg.getAlignment(),
-                 LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
+                 LValueBaseInfo(AlignmentSource::Decl, TBAAAccessInfo()));
     return R;
   }
 
Index: CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- CodeGen/CGOpenMPRuntime.cpp
+++ CodeGen/CGOpenMPRuntime.cpp
@@ -989,11 +989,13 @@
   PrivateAddr = CGF.Builder.CreateElementBitCast(
       PrivateAddr, CGF.ConvertTypeForMem(PrivateType));
   QualType SharedType = SharedAddresses[N].first.getType();
+  LValueBaseInfo BaseInfo(
+      SharedAddresses[N].first.getAlignmentSource(),
+      CGF.CGM.getTBAAInfoForSubobject(SharedAddresses[N].first, SharedType));
   SharedLVal = CGF.MakeAddrLValue(
       CGF.Builder.CreateElementBitCast(SharedLVal.getAddress(),
                                        CGF.ConvertTypeForMem(SharedType)),
-      SharedType, SharedAddresses[N].first.getBaseInfo(),
-      CGF.CGM.getTBAAInfoForSubobject(SharedAddresses[N].first, SharedType));
+      SharedType, BaseInfo);
   if (isa<OMPArraySectionExpr>(ClausesData[N].Ref) ||
       CGF.getContext().getAsArrayType(PrivateVD->getType())) {
     emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
@@ -1043,11 +1045,13 @@
     }
     BaseTy = BaseTy->getPointeeType();
   }
+  LValueBaseInfo BaseInfo(
+      BaseLV.getAlignmentSource(),
+      CGF.CGM.getTBAAInfoForSubobject(BaseLV, BaseLV.getType()));
   return CGF.MakeAddrLValue(
       CGF.Builder.CreateElementBitCast(BaseLV.getAddress(),
                                        CGF.ConvertTypeForMem(ElTy)),
-      BaseLV.getType(), BaseLV.getBaseInfo(),
-      CGF.CGM.getTBAAInfoForSubobject(BaseLV, BaseLV.getType()));
+      BaseLV.getType(), BaseInfo);
 }
 
 static Address castToBase(CodeGenFunction &CGF, QualType BaseTy, QualType ElTy,
@@ -4085,8 +4089,8 @@
         SharedRefLValue = CGF.MakeAddrLValue(
             Address(SharedRefLValue.getPointer(), C.getDeclAlign(OriginalVD)),
             SharedRefLValue.getType(),
-            LValueBaseInfo(AlignmentSource::Decl),
-            SharedRefLValue.getTBAAInfo());
+            LValueBaseInfo(AlignmentSource::Decl,
+                           SharedRefLValue.getTBAAInfo()));
         QualType Type = OriginalVD->getType();
         if (Type->isArrayType()) {
           // Initialize firstprivate array.
Index: CodeGen/CGObjCRuntime.cpp
===================================================================
--- CodeGen/CGObjCRuntime.cpp
+++ CodeGen/CGObjCRuntime.cpp
@@ -110,8 +110,8 @@
                                    llvm::Type::getIntNTy(CGF.getLLVMContext(),
                                                          Info->StorageSize));
   return LValue::MakeBitfield(Addr, *Info, IvarTy,
-                              LValueBaseInfo(AlignmentSource::Decl),
-                              TBAAAccessInfo());
+                              LValueBaseInfo(AlignmentSource::Decl,
+                                             TBAAAccessInfo()));
 }
 
 namespace {
Index: CodeGen/CGExpr.cpp
===================================================================
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -916,8 +916,7 @@
 /// EmitPointerWithAlignment - Given an expression of pointer type, try to
 /// derive a more accurate bound on the alignment of the pointer.
 Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
-                                                  LValueBaseInfo *BaseInfo,
-                                                  TBAAAccessInfo *TBAAInfo) {
+                                                  LValueBaseInfo *BaseInfo) {
   // We allow this with ObjC object pointers because of fragile ABIs.
   assert(E->getType()->isPointerType() ||
          E->getType()->isObjCObjectPointerType());
@@ -938,27 +937,26 @@
           break;
 
         LValueBaseInfo InnerBaseInfo;
-        TBAAAccessInfo InnerTBAAInfo;
         Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
-                                                &InnerBaseInfo,
-                                                &InnerTBAAInfo);
+                                                &InnerBaseInfo);
         if (BaseInfo) *BaseInfo = InnerBaseInfo;
-        if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
 
         if (isa<ExplicitCastExpr>(CE)) {
           LValueBaseInfo TargetTypeBaseInfo;
-          TBAAAccessInfo TargetTypeTBAAInfo;
           CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(),
-                                                           &TargetTypeBaseInfo,
-                                                           &TargetTypeTBAAInfo);
-          if (TBAAInfo)
-            *TBAAInfo = CGM.mergeTBAAInfoForCast(*TBAAInfo,
-                                                 TargetTypeTBAAInfo);
+                                                           &TargetTypeBaseInfo);
+          if (BaseInfo) {
+            TBAAAccessInfo MergedTBAAInfo =
+                CGM.mergeTBAAInfoForCast(BaseInfo->getTBAAInfo(),
+                                         TargetTypeBaseInfo.getTBAAInfo());
+            BaseInfo->setTBAAInfo(MergedTBAAInfo);
+          }
+
           // If the source l-value is opaque, honor the alignment of the
           // casted-to type.
           if (InnerBaseInfo.getAlignmentSource() != AlignmentSource::Decl) {
             if (BaseInfo)
-              BaseInfo->mergeForCast(TargetTypeBaseInfo);
+              BaseInfo->mergeForCast(TargetTypeBaseInfo, CGM);
             Addr = Address(Addr.getPointer(), Align);
           }
         }
@@ -980,13 +978,12 @@
 
     // Array-to-pointer decay.
     case CK_ArrayToPointerDecay:
-      return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo, TBAAInfo);
+      return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo);
 
     // Derived-to-base conversions.
     case CK_UncheckedDerivedToBase:
     case CK_DerivedToBase: {
-      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
-                                              TBAAInfo);
+      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
       auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
       return GetAddressOfBaseClass(Addr, Derived,
                                    CE->path_begin(), CE->path_end(),
@@ -1006,16 +1003,14 @@
     if (UO->getOpcode() == UO_AddrOf) {
       LValue LV = EmitLValue(UO->getSubExpr());
       if (BaseInfo) *BaseInfo = LV.getBaseInfo();
-      if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();
       return LV.getAddress();
     }
   }
 
   // TODO: conditional operators, comma.
 
   // Otherwise, use the alignment of the type.
-  CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(), BaseInfo,
-                                                   TBAAInfo);
+  CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(), BaseInfo);
   return Address(EmitScalarExpr(E), Align);
 }
 
@@ -1184,7 +1179,7 @@
       llvm::Value *V = LV.getPointer();
       Scope.ForceCleanup({&V});
       return LValue::MakeAddr(Address(V, LV.getAlignment()), LV.getType(),
-                              getContext(), LV.getBaseInfo(), LV.getTBAAInfo());
+                              getContext(), LV.getBaseInfo());
     }
     // FIXME: Is it possible to create an ExprWithCleanups that produces a
     // bitfield lvalue or some other non-simple lvalue?
@@ -1384,7 +1379,7 @@
                                                SourceLocation Loc) {
   return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),
                           lvalue.getType(), Loc, lvalue.getBaseInfo(),
-                          lvalue.getTBAAInfo(), lvalue.isNontemporal());
+                          lvalue.isNontemporal());
 }
 
 static bool hasBooleanRepresentation(QualType Ty) {
@@ -1494,7 +1489,6 @@
                                                QualType Ty,
                                                SourceLocation Loc,
                                                LValueBaseInfo BaseInfo,
-                                               TBAAAccessInfo TBAAInfo,
                                                bool isNontemporal) {
   if (!CGM.getCodeGenOpts().PreserveVec3Type) {
     // For better performance, handle vector loads differently.
@@ -1522,8 +1516,7 @@
   }
 
   // Atomic operations have to be done on integral types.
-  LValue AtomicLValue =
-      LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
+  LValue AtomicLValue = LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo);
   if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) {
     return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal();
   }
@@ -1535,7 +1528,7 @@
     Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
 
-  CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
+  CGM.DecorateInstructionWithTBAA(Load, BaseInfo.getTBAAInfo());
 
   if (EmitScalarRangeCheck(Load, Ty, Loc)) {
     // In order to prevent the optimizer from throwing away the check, don't
@@ -1575,7 +1568,6 @@
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
                                         bool Volatile, QualType Ty,
                                         LValueBaseInfo BaseInfo,
-                                        TBAAAccessInfo TBAAInfo,
                                         bool isInit, bool isNontemporal) {
   if (!CGM.getCodeGenOpts().PreserveVec3Type) {
     // Handle vectors differently to get better performance.
@@ -1601,8 +1593,7 @@
 
   Value = EmitToMemory(Value, Ty);
 
-  LValue AtomicLValue =
-      LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
+  LValue AtomicLValue = LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo);
   if (Ty->isAtomicType() ||
       (!isInit && LValueIsSuitableForInlineAtomic(AtomicLValue))) {
     EmitAtomicStore(RValue::get(Value), AtomicLValue, isInit);
@@ -1617,14 +1608,14 @@
     Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
 
-  CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
+  CGM.DecorateInstructionWithTBAA(Store, BaseInfo.getTBAAInfo());
 }
 
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
                                         bool isInit) {
   EmitStoreOfScalar(value, lvalue.getAddress(), lvalue.isVolatile(),
                     lvalue.getType(), lvalue.getBaseInfo(),
-                    lvalue.getTBAAInfo(), isInit, lvalue.isNontemporal());
+                    isInit, lvalue.isNontemporal());
 }
 
 /// EmitLoadOfLValue - Given an expression that represents a value lvalue, this
@@ -2159,38 +2150,34 @@
 
 Address CodeGenFunction::EmitLoadOfReference(Address Addr,
                                              const ReferenceType *RefTy,
-                                             LValueBaseInfo *BaseInfo,
-                                             TBAAAccessInfo *TBAAInfo) {
+                                             LValueBaseInfo *BaseInfo) {
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
-                                              BaseInfo, TBAAInfo,
+                                              BaseInfo,
                                               /* forPointeeType= */ true));
 }
 
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
                                                   const ReferenceType *RefTy) {
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
-  Address Addr = EmitLoadOfReference(RefAddr, RefTy, &BaseInfo, &TBAAInfo);
-  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo, TBAAInfo);
+  Address Addr = EmitLoadOfReference(RefAddr, RefTy, &BaseInfo);
+  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo);
 }
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
                                            const PointerType *PtrTy,
-                                           LValueBaseInfo *BaseInfo,
-                                           TBAAAccessInfo *TBAAInfo) {
+                                           LValueBaseInfo *BaseInfo) {
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
-                                               BaseInfo, TBAAInfo,
+                                               BaseInfo,
                                                /*forPointeeType=*/true));
 }
 
 LValue CodeGenFunction::EmitLoadOfPointerLValue(Address PtrAddr,
                                                 const PointerType *PtrTy) {
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
-  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, &BaseInfo, &TBAAInfo);
-  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo, TBAAInfo);
+  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, &BaseInfo);
+  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo);
 }
 
 static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF,
@@ -2322,7 +2309,6 @@
       // Should we be using the alignment of the constant pointer we emitted?
       CharUnits Alignment = getNaturalTypeAlignment(E->getType(),
                                                     /* BaseInfo= */ nullptr,
-                                                    /* TBAAInfo= */ nullptr,
                                                     /* forPointeeType= */ true);
       return MakeAddrLValue(Address(Val, Alignment), T, AlignmentSource::Decl);
     }
@@ -2344,8 +2330,8 @@
                                     CapturedStmtInfo->getContextValue());
         return MakeAddrLValue(
             Address(CapLVal.getPointer(), getContext().getDeclAlign(VD)),
-            CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl),
-            CapLVal.getTBAAInfo());
+            CapLVal.getType(),
+            LValueBaseInfo(AlignmentSource::Decl, CapLVal.getTBAAInfo()));
       }
 
       assert(isa<BlockDecl>(CurCodeDecl));
@@ -2456,10 +2442,8 @@
     assert(!T.isNull() && "CodeGenFunction::EmitUnaryOpLValue: Illegal type");
 
     LValueBaseInfo BaseInfo;
-    TBAAAccessInfo TBAAInfo;
-    Address Addr = EmitPointerWithAlignment(E->getSubExpr(), &BaseInfo,
-                                            &TBAAInfo);
-    LValue LV = MakeAddrLValue(Addr, T, BaseInfo, TBAAInfo);
+    Address Addr = EmitPointerWithAlignment(E->getSubExpr(), &BaseInfo);
+    LValue LV = MakeAddrLValue(Addr, T, BaseInfo);
     LV.getQuals().setAddressSpace(ExprTy.getAddressSpace());
 
     // We should not generate __weak write barrier on indirect reference
@@ -2491,8 +2475,9 @@
       (E->getOpcode() == UO_Real
          ? emitAddrOfRealComponent(LV.getAddress(), LV.getType())
          : emitAddrOfImagComponent(LV.getAddress(), LV.getType()));
-    LValue ElemLV = MakeAddrLValue(Component, T, LV.getBaseInfo(),
-                                   CGM.getTBAAInfoForSubobject(LV, T));
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, T));
+    LValue ElemLV = MakeAddrLValue(Component, T, BaseInfo);
     ElemLV.getQuals().addQualifiers(LV.getQuals());
     return ElemLV;
   }
@@ -3059,16 +3044,14 @@
 }
 
 Address CodeGenFunction::EmitArrayToPointerDecay(const Expr *E,
-                                                 LValueBaseInfo *BaseInfo,
-                                                 TBAAAccessInfo *TBAAInfo) {
+                                                 LValueBaseInfo *BaseInfo) {
   assert(E->getType()->isArrayType() &&
          "Array to pointer decay must have array source type!");
 
   // Expressions of array type can't be bitfields or vector elements.
   LValue LV = EmitLValue(E);
   Address Addr = LV.getAddress();
   if (BaseInfo) *BaseInfo = LV.getBaseInfo();
-  if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();
 
   // If the array type was an incomplete type, we need to make sure
   // the decay ends up being the right type.
@@ -3209,7 +3192,8 @@
     auto *Idx = EmitIdxAfterBase(/*Promote*/false);
     assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
     return LValue::MakeVectorElt(LHS.getAddress(), Idx, E->getBase()->getType(),
-                                 LHS.getBaseInfo(), TBAAAccessInfo());
+                                 LValueBaseInfo(LHS.getAlignmentSource(),
+                                                TBAAAccessInfo()));
   }
 
   // All the other cases basically behave like simple offsetting.
@@ -3223,19 +3207,20 @@
     QualType EltType = LV.getType()->castAs<VectorType>()->getElementType();
     Addr = emitArraySubscriptGEP(*this, Addr, Idx, EltType, /*inbounds*/ true,
                                  SignedIndices, E->getExprLoc());
-    return MakeAddrLValue(Addr, EltType, LV.getBaseInfo(),
-                          CGM.getTBAAInfoForSubobject(LV, EltType));
+
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, EltType));
+    return MakeAddrLValue(Addr, EltType, BaseInfo);
   }
 
   LValueBaseInfo EltBaseInfo;
-  TBAAAccessInfo EltTBAAInfo;
   Address Addr = Address::invalid();
   if (const VariableArrayType *vla =
            getContext().getAsVariableArrayType(E->getType())) {
     // The base must be a pointer, which is not an aggregate.  Emit
     // it.  It needs to be emitted first in case it's what captures
     // the VLA bounds.
-    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo, &EltTBAAInfo);
+    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo);
     auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
     // The element count here is the total number of non-VLA elements.
@@ -3259,7 +3244,7 @@
     // Indexing over an interface, as in "NSString *P; P[4];"
 
     // Emit the base pointer.
-    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo, &EltTBAAInfo);
+    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo);
     auto *Idx = EmitIdxAfterBase(/*Promote*/true);
 
     CharUnits InterfaceSize = getContext().getTypeSizeInChars(OIT);
@@ -3306,18 +3291,19 @@
         *this, ArrayLV.getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},
         E->getType(), !getLangOpts().isSignedOverflowDefined(), SignedIndices,
         E->getExprLoc());
-    EltBaseInfo = ArrayLV.getBaseInfo();
-    EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
+    EltBaseInfo = LValueBaseInfo(
+        ArrayLV.getAlignmentSource(),
+        CGM.getTBAAInfoForSubobject(ArrayLV, E->getType()));
   } else {
     // The base must be a pointer; emit it with an estimate of its alignment.
-    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo, &EltTBAAInfo);
+    Addr = EmitPointerWithAlignment(E->getBase(), &EltBaseInfo);
     auto *Idx = EmitIdxAfterBase(/*Promote*/true);
     Addr = emitArraySubscriptGEP(*this, Addr, Idx, E->getType(),
                                  !getLangOpts().isSignedOverflowDefined(),
                                  SignedIndices, E->getExprLoc());
   }
 
-  LValue LV = MakeAddrLValue(Addr, E->getType(), EltBaseInfo, EltTBAAInfo);
+  LValue LV = MakeAddrLValue(Addr, E->getType(), EltBaseInfo);
 
   if (getLangOpts().ObjC1 &&
       getLangOpts().getGC() != LangOptions::NonGC) {
@@ -3329,7 +3315,6 @@
 
 static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base,
                                        LValueBaseInfo &BaseInfo,
-                                       TBAAAccessInfo &TBAAInfo,
                                        QualType BaseTy, QualType ElTy,
                                        bool IsLowerBound) {
   LValue BaseLVal;
@@ -3357,14 +3342,11 @@
                                               CGF.ConvertTypeForMem(ElTy));
     }
     LValueBaseInfo TypeBaseInfo;
-    TBAAAccessInfo TypeTBAAInfo;
-    CharUnits Align = CGF.getNaturalTypeAlignment(ElTy, &TypeBaseInfo,
-                                                  &TypeTBAAInfo);
-    BaseInfo.mergeForCast(TypeBaseInfo);
-    TBAAInfo = CGF.CGM.mergeTBAAInfoForCast(TBAAInfo, TypeTBAAInfo);
+    CharUnits Align = CGF.getNaturalTypeAlignment(ElTy, &TypeBaseInfo);
+    BaseInfo.mergeForCast(TypeBaseInfo, CGF.CGM);
     return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress()), Align);
   }
-  return CGF.EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
+  return CGF.EmitPointerWithAlignment(Base, &BaseInfo);
 }
 
 LValue CodeGenFunction::EmitOMPArraySectionExpr(const OMPArraySectionExpr *E,
@@ -3464,13 +3446,12 @@
 
   Address EltPtr = Address::invalid();
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
   if (auto *VLA = getContext().getAsVariableArrayType(ResultExprTy)) {
     // The base must be a pointer, which is not an aggregate.  Emit
     // it.  It needs to be emitted first in case it's what captures
     // the VLA bounds.
     Address Base =
-        emitOMPArraySectionBase(*this, E->getBase(), BaseInfo, TBAAInfo,
+        emitOMPArraySectionBase(*this, E->getBase(), BaseInfo,
                                 BaseTy, VLA->getElementType(), IsLowerBound);
     // The element count here is the total number of non-VLA elements.
     llvm::Value *NumElements = getVLASize(VLA).first;
@@ -3506,18 +3487,18 @@
         *this, ArrayLV.getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},
         ResultExprTy, !getLangOpts().isSignedOverflowDefined(),
         /*SignedIndices=*/false, E->getExprLoc());
-    BaseInfo = ArrayLV.getBaseInfo();
-    TBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, ResultExprTy);
+    BaseInfo = LValueBaseInfo(
+        ArrayLV.getAlignmentSource(),
+        CGM.getTBAAInfoForSubobject(ArrayLV, ResultExprTy));
   } else {
     Address Base = emitOMPArraySectionBase(*this, E->getBase(), BaseInfo,
-                                           TBAAInfo, BaseTy, ResultExprTy,
-                                           IsLowerBound);
+                                           BaseTy, ResultExprTy, IsLowerBound);
     EltPtr = emitArraySubscriptGEP(*this, Base, Idx, ResultExprTy,
                                    !getLangOpts().isSignedOverflowDefined(),
                                    /*SignedIndices=*/false, E->getExprLoc());
   }
 
-  return MakeAddrLValue(EltPtr, ResultExprTy, BaseInfo, TBAAInfo);
+  return MakeAddrLValue(EltPtr, ResultExprTy, BaseInfo);
 }
 
 LValue CodeGenFunction::
@@ -3530,10 +3511,9 @@
     // If it is a pointer to a vector, emit the address and form an lvalue with
     // it.
     LValueBaseInfo BaseInfo;
-    TBAAAccessInfo TBAAInfo;
-    Address Ptr = EmitPointerWithAlignment(E->getBase(), &BaseInfo, &TBAAInfo);
+    Address Ptr = EmitPointerWithAlignment(E->getBase(), &BaseInfo);
     const PointerType *PT = E->getBase()->getType()->getAs<PointerType>();
-    Base = MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo, TBAAInfo);
+    Base = MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo);
     Base.getQuals().removeObjCGCAttr();
   } else if (E->getBase()->isGLValue()) {
     // Otherwise, if the base is an lvalue ( as in the case of foo.x.x),
@@ -3563,8 +3543,9 @@
   if (Base.isSimple()) {
     llvm::Constant *CV =
         llvm::ConstantDataVector::get(getLLVMContext(), Indices);
-    return LValue::MakeExtVectorElt(Base.getAddress(), CV, type,
-                                    Base.getBaseInfo(), TBAAAccessInfo());
+    return LValue::MakeExtVectorElt(
+        Base.getAddress(), CV, type,
+        LValueBaseInfo(Base.getAlignmentSource(), TBAAAccessInfo()));
   }
   assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");
 
@@ -3574,8 +3555,9 @@
   for (unsigned i = 0, e = Indices.size(); i != e; ++i)
     CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
   llvm::Constant *CV = llvm::ConstantVector::get(CElts);
-  return LValue::MakeExtVectorElt(Base.getExtVectorAddress(), CV, type,
-                                  Base.getBaseInfo(), TBAAAccessInfo());
+  return LValue::MakeExtVectorElt(
+      Base.getExtVectorAddress(), CV, type,
+      LValueBaseInfo(Base.getAlignmentSource(), TBAAAccessInfo()));
 }
 
 LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
@@ -3589,8 +3571,7 @@
   LValue BaseLV;
   if (E->isArrow()) {
     LValueBaseInfo BaseInfo;
-    TBAAAccessInfo TBAAInfo;
-    Address Addr = EmitPointerWithAlignment(BaseExpr, &BaseInfo, &TBAAInfo);
+    Address Addr = EmitPointerWithAlignment(BaseExpr, &BaseInfo);
     QualType PtrTy = BaseExpr->getType()->getPointeeType();
     SanitizerSet SkippedChecks;
     bool IsBaseCXXThis = IsWrappedCXXThis(BaseExpr);
@@ -3600,7 +3581,7 @@
       SkippedChecks.set(SanitizerKind::Null, true);
     EmitTypeCheck(TCK_MemberAccess, E->getExprLoc(), Addr.getPointer(), PtrTy,
                   /*Alignment=*/CharUnits::Zero(), SkippedChecks);
-    BaseLV = MakeAddrLValue(Addr, PtrTy, BaseInfo, TBAAInfo);
+    BaseLV = MakeAddrLValue(Addr, PtrTy, BaseInfo);
   } else
     BaseLV = EmitCheckedLValue(BaseExpr, TCK_MemberAccess);
 
@@ -3697,9 +3678,9 @@
     QualType fieldType =
       field->getType().withCVRQualifiers(base.getVRQualifiers());
     // TODO: Support TBAA for bit fields.
-    LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource());
-    return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
-                                TBAAAccessInfo());
+    LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource(),
+                                 TBAAAccessInfo());
+    return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo);
   }
 
   // Fields of may-alias structures are may-alias themselves.
@@ -3709,17 +3690,16 @@
   const RecordDecl *rec = field->getParent();
   AlignmentSource BaseAlignSource = BaseInfo.getAlignmentSource();
   LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(BaseAlignSource));
-  TBAAAccessInfo FieldTBAAInfo;
   if (CGM.isTBAAMayAliasAccessInfo(base.getTBAAInfo()) ||
           rec->hasAttr<MayAliasAttr>() || FieldType->isVectorType()) {
-    FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+    FieldBaseInfo.setTBAAInfo(CGM.getTBAAMayAliasAccessInfo());
   } else if (rec->isUnion()) {
     // TODO: Support TBAA for unions.
-    FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+    FieldBaseInfo.setTBAAInfo(CGM.getTBAAMayAliasAccessInfo());
   } else {
     // If no base type been assigned for the base access, then try to generate
     // one for this base lvalue.
-    FieldTBAAInfo = base.getTBAAInfo();
+    TBAAAccessInfo FieldTBAAInfo = base.getTBAAInfo();
     if (!FieldTBAAInfo.BaseType) {
         FieldTBAAInfo.BaseType = CGM.getTBAABaseTypeInfo(base.getType());
         assert(!FieldTBAAInfo.Offset &&
@@ -3736,6 +3716,8 @@
 
     // Update the final access type.
     FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(FieldType);
+
+    FieldBaseInfo.setTBAAInfo(FieldTBAAInfo);
   }
 
   Address addr = base.getAddress();
@@ -3758,11 +3740,10 @@
       llvm::LoadInst *load = Builder.CreateLoad(addr, "ref");
       if (cvr & Qualifiers::Volatile) load->setVolatile(true);
 
-      CGM.DecorateInstructionWithTBAA(load, FieldTBAAInfo);
+      CGM.DecorateInstructionWithTBAA(load, FieldBaseInfo.getTBAAInfo());
 
       FieldType = refType->getPointeeType();
       CharUnits Align = getNaturalTypeAlignment(FieldType, &FieldBaseInfo,
-                                                &FieldTBAAInfo,
                                                 /* forPointeeType= */ true);
       addr = Address(load, Align);
 
@@ -3783,7 +3764,7 @@
   if (field->hasAttr<AnnotateAttr>())
     addr = EmitFieldAnnotations(field, addr);
 
-  LValue LV = MakeAddrLValue(addr, FieldType, FieldBaseInfo, FieldTBAAInfo);
+  LValue LV = MakeAddrLValue(addr, FieldType, FieldBaseInfo);
   LV.getQuals().addCVRQualifiers(cvr);
 
   // __weak attribute on a field is ignored.
@@ -3812,9 +3793,9 @@
   // should be similar to what we do in EmitLValueForField().
   LValueBaseInfo BaseInfo = Base.getBaseInfo();
   AlignmentSource FieldAlignSource = BaseInfo.getAlignmentSource();
-  LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(FieldAlignSource));
-  return MakeAddrLValue(V, FieldType, FieldBaseInfo,
-                        CGM.getTBAAInfoForSubobject(Base, FieldType));
+  LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(FieldAlignSource),
+                               CGM.getTBAAInfoForSubobject(Base, FieldType));
+  return MakeAddrLValue(V, FieldType, FieldBaseInfo);
 }
 
 LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr *E){
@@ -3924,13 +3905,12 @@
     phi->addIncoming(lhs->getPointer(), lhsBlock);
     phi->addIncoming(rhs->getPointer(), rhsBlock);
     Address result(phi, std::min(lhs->getAlignment(), rhs->getAlignment()));
-    AlignmentSource alignSource =
-      std::max(lhs->getBaseInfo().getAlignmentSource(),
-               rhs->getBaseInfo().getAlignmentSource());
+    AlignmentSource alignSource = std::max(lhs->getAlignmentSource(),
+                                           rhs->getAlignmentSource());
     TBAAAccessInfo TBAAInfo = CGM.mergeTBAAInfoForConditionalOperator(
         lhs->getTBAAInfo(), rhs->getTBAAInfo());
-    return MakeAddrLValue(result, expr->getType(), LValueBaseInfo(alignSource),
-                          TBAAInfo);
+    return MakeAddrLValue(result, expr->getType(),
+                          LValueBaseInfo(alignSource, TBAAInfo));
   } else {
     assert((lhs || rhs) &&
            "both operands of glvalue conditional are throw-expressions?");
@@ -4031,8 +4011,9 @@
     // 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.
-    return MakeAddrLValue(Base, E->getType(), LV.getBaseInfo(),
-                          CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    return MakeAddrLValue(Base, E->getType(), BaseInfo);
   }
   case CK_ToUnion:
     return EmitAggExprToLValue(E);
@@ -4059,8 +4040,9 @@
                                 /*MayBeNull=*/false,
                                 CFITCK_DerivedCast, E->getLocStart());
 
-    return MakeAddrLValue(Derived, E->getType(), LV.getBaseInfo(),
-                          CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    return MakeAddrLValue(Derived, E->getType(), BaseInfo);
   }
   case CK_LValueBitCast: {
     // This must be a reinterpret_cast (or c-style equivalent).
@@ -4076,15 +4058,17 @@
                                 /*MayBeNull=*/false,
                                 CFITCK_UnrelatedCast, E->getLocStart());
 
-    return MakeAddrLValue(V, E->getType(), LV.getBaseInfo(),
-                          CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    return MakeAddrLValue(V, E->getType(), BaseInfo);
   }
   case CK_ObjCObjectLValueCast: {
     LValue LV = EmitLValue(E->getSubExpr());
     Address V = Builder.CreateElementBitCast(LV.getAddress(),
                                              ConvertType(E->getType()));
-    return MakeAddrLValue(V, E->getType(), LV.getBaseInfo(),
-                          CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    LValueBaseInfo BaseInfo(LV.getAlignmentSource(),
+                            CGM.getTBAAInfoForSubobject(LV, E->getType()));
+    return MakeAddrLValue(V, E->getType(), BaseInfo);
   }
   case CK_ZeroToOCLQueue:
     llvm_unreachable("NULL to OpenCL queue lvalue cast is not valid");
@@ -4579,12 +4563,10 @@
     = E->getRHS()->getType()->getAs<MemberPointerType>();
 
   LValueBaseInfo BaseInfo;
-  TBAAAccessInfo TBAAInfo;
   Address MemberAddr =
-    EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, &BaseInfo,
-                                    &TBAAInfo);
+    EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, &BaseInfo);
 
-  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
+  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo);
 }
 
 /// Given the address of a temporary variable, produce an r-value of
@@ -4696,3 +4678,9 @@
 LValue CodeGenFunction::EmitPseudoObjectLValue(const PseudoObjectExpr *E) {
   return emitPseudoObjectExpr(*this, E, true, AggValueSlot::ignored()).LV;
 }
+
+void LValueBaseInfo::mergeForCast(const LValueBaseInfo &Info,
+                                  CodeGenModule &CGM) {
+  setAlignmentSource(Info.getAlignmentSource());
+  setTBAAInfo(CGM.mergeTBAAInfoForCast(getTBAAInfo(), Info.getTBAAInfo()));
+}
Index: CodeGen/CGClass.cpp
===================================================================
--- CodeGen/CGClass.cpp
+++ CodeGen/CGClass.cpp
@@ -129,16 +129,14 @@
 CodeGenFunction::EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
                                                  llvm::Value *memberPtr,
                                       const MemberPointerType *memberPtrType,
-                                                 LValueBaseInfo *BaseInfo,
-                                                 TBAAAccessInfo *TBAAInfo) {
+                                                 LValueBaseInfo *BaseInfo) {
   // Ask the ABI to compute the actual address.
   llvm::Value *ptr =
     CGM.getCXXABI().EmitMemberDataPointerAddress(*this, E, base,
                                                  memberPtr, memberPtrType);
 
   QualType memberType = memberPtrType->getPointeeType();
-  CharUnits memberAlign = getNaturalTypeAlignment(memberType, BaseInfo,
-                                                  TBAAInfo);
+  CharUnits memberAlign = getNaturalTypeAlignment(memberType, BaseInfo);
   memberAlign =
     CGM.getDynamicOffsetAlignment(base.getAlignment(),
                             memberPtrType->getClass()->getAsCXXRecordDecl(),
Index: CodeGen/CGAtomic.cpp
===================================================================
--- CodeGen/CGAtomic.cpp
+++ CodeGen/CGAtomic.cpp
@@ -96,8 +96,8 @@
         BFI.StorageSize = AtomicSizeInBits;
         BFI.StorageOffset += OffsetInChars;
         LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
-                                    BFI, lvalue.getType(), lvalue.getBaseInfo(),
-                                    lvalue.getTBAAInfo());
+                                    BFI, lvalue.getType(),
+                                    lvalue.getBaseInfo());
         AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
         if (AtomicTy.isNull()) {
           llvm::APInt Size(
@@ -204,7 +204,7 @@
         addr = CGF.Builder.CreateStructGEP(addr, 0, CharUnits());
 
       return LValue::MakeAddr(addr, getValueType(), CGF.getContext(),
-                              LVal.getBaseInfo(), LVal.getTBAAInfo());
+                              LVal.getBaseInfo());
     }
 
     /// \brief Emits atomic load.
@@ -1347,15 +1347,19 @@
   if (LVal.isBitField())
     return CGF.EmitLoadOfBitfieldLValue(
         LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(),
-                             LVal.getBaseInfo(), TBAAAccessInfo()), loc);
+                             LValueBaseInfo(LVal.getAlignmentSource(),
+                                            TBAAAccessInfo())),
+                             loc);
   if (LVal.isVectorElt())
     return CGF.EmitLoadOfLValue(
         LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(),
-                              LVal.getBaseInfo(), TBAAAccessInfo()), loc);
+                              LValueBaseInfo(LVal.getAlignmentSource(),
+                                             TBAAAccessInfo())),
+                              loc);
   assert(LVal.isExtVectorElt());
   return CGF.EmitLoadOfExtVectorElementLValue(LValue::MakeExtVectorElt(
       addr, LVal.getExtVectorElts(), LVal.getType(),
-      LVal.getBaseInfo(), TBAAAccessInfo()));
+      LValueBaseInfo(LVal.getAlignmentSource(), TBAAAccessInfo())));
 }
 
 RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
@@ -1671,29 +1675,25 @@
       UpdateLVal =
           LValue::MakeBitfield(Ptr, AtomicLVal.getBitFieldInfo(),
                                AtomicLVal.getType(),
-                               AtomicLVal.getBaseInfo(),
-                               AtomicLVal.getTBAAInfo());
+                               AtomicLVal.getBaseInfo());
       DesiredLVal =
           LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
-                               AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
-                               AtomicLVal.getTBAAInfo());
+                               AtomicLVal.getType(), AtomicLVal.getBaseInfo());
     } else if (AtomicLVal.isVectorElt()) {
       UpdateLVal = LValue::MakeVectorElt(Ptr, AtomicLVal.getVectorIdx(),
                                          AtomicLVal.getType(),
-                                         AtomicLVal.getBaseInfo(),
-                                         AtomicLVal.getTBAAInfo());
+                                         AtomicLVal.getBaseInfo());
       DesiredLVal = LValue::MakeVectorElt(
           DesiredAddr, AtomicLVal.getVectorIdx(), AtomicLVal.getType(),
-          AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
+          AtomicLVal.getBaseInfo());
     } else {
       assert(AtomicLVal.isExtVectorElt());
       UpdateLVal = LValue::MakeExtVectorElt(Ptr, AtomicLVal.getExtVectorElts(),
                                             AtomicLVal.getType(),
-                                            AtomicLVal.getBaseInfo(),
-                                            AtomicLVal.getTBAAInfo());
+                                            AtomicLVal.getBaseInfo());
       DesiredLVal = LValue::MakeExtVectorElt(
           DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
-          AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
+          AtomicLVal.getBaseInfo());
     }
     UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
@@ -1777,18 +1777,16 @@
   if (AtomicLVal.isBitField()) {
     DesiredLVal =
         LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
-                             AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
-                             AtomicLVal.getTBAAInfo());
+                             AtomicLVal.getType(), AtomicLVal.getBaseInfo());
   } else if (AtomicLVal.isVectorElt()) {
     DesiredLVal =
         LValue::MakeVectorElt(DesiredAddr, AtomicLVal.getVectorIdx(),
-                              AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
-                              AtomicLVal.getTBAAInfo());
+                              AtomicLVal.getType(), AtomicLVal.getBaseInfo());
   } else {
     assert(AtomicLVal.isExtVectorElt());
     DesiredLVal = LValue::MakeExtVectorElt(
         DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
-        AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
+        AtomicLVal.getBaseInfo());
   }
   // Store new value in the corresponding memory area
   assert(UpdateRVal.isScalar());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to