<div dir="ltr">Hi,<div><br></div><div>This commit has caused a new regression in LLVM 6. I filed the following PR: <a href="https://bugs.llvm.org/show_bug.cgi?id=35724">https://bugs.llvm.org/show_bug.cgi?id=35724</a> . </div><div>Could you please take a look?</div><div><br></div><div>Thanks,</div><div>Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 17 October 2017 at 02:12, Ivan A. Kosarev via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kosarev<br>
Date: Tue Oct 17 02:12:13 2017<br>
New Revision: 315984<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=315984&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=315984&view=rev</a><br>
Log:<br>
[CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D38796" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D38796</a><br>
<br>
Added:<br>
cfe/trunk/test/CodeGen/tbaa-<wbr>cast.cpp<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGExpr.<wbr>cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.h<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.h<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGExpr.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGExpr.cpp?rev=315984&r1=<wbr>315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/CGExpr.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGExpr.<wbr>cpp Tue Oct 17 02:12:13 2017<br>
@@ -916,7 +916,8 @@ void CodeGenModule::<wbr>EmitExplicitCastExpr<br>
/// EmitPointerWithAlignment - Given an expression of pointer type, try to<br>
/// derive a more accurate bound on the alignment of the pointer.<br>
Address CodeGenFunction::<wbr>EmitPointerWithAlignment(const Expr *E,<br>
- LValueBaseInfo *BaseInfo) {<br>
+ LValueBaseInfo *BaseInfo,<br>
+ TBAAAccessInfo *TBAAInfo) {<br>
// We allow this with ObjC object pointers because of fragile ABIs.<br>
assert(E->getType()-><wbr>isPointerType() ||<br>
E->getType()-><wbr>isObjCObjectPointerType());<br>
@@ -936,20 +937,30 @@ Address CodeGenFunction::<wbr>EmitPointerWith<br>
if (PtrTy->getPointeeType()-><wbr>isVoidType())<br>
break;<br>
<br>
- LValueBaseInfo InnerInfo;<br>
- Address Addr = EmitPointerWithAlignment(CE-><wbr>getSubExpr(), &InnerInfo);<br>
- if (BaseInfo) *BaseInfo = InnerInfo;<br>
-<br>
- // If this is an explicit bitcast, and the source l-value is<br>
- // opaque, honor the alignment of the casted-to type.<br>
- if (isa<ExplicitCastExpr>(CE) &&<br>
- InnerInfo.getAlignmentSource() != AlignmentSource::Decl) {<br>
- LValueBaseInfo ExpInfo;<br>
+ LValueBaseInfo InnerBaseInfo;<br>
+ TBAAAccessInfo InnerTBAAInfo;<br>
+ Address Addr = EmitPointerWithAlignment(CE-><wbr>getSubExpr(),<br>
+ &InnerBaseInfo,<br>
+ &InnerTBAAInfo);<br>
+ if (BaseInfo) *BaseInfo = InnerBaseInfo;<br>
+ if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;<br>
+<br>
+ if (isa<ExplicitCastExpr>(CE)) {<br>
+ LValueBaseInfo TargetTypeBaseInfo;<br>
+ TBAAAccessInfo TargetTypeTBAAInfo;<br>
CharUnits Align = getNaturalPointeeTypeAlignment<wbr>(E->getType(),<br>
- &ExpInfo);<br>
- if (BaseInfo)<br>
- BaseInfo->mergeForCast(<wbr>ExpInfo);<br>
- Addr = Address(Addr.getPointer(), Align);<br>
+ &TargetTypeBaseInfo,<br>
+ &TargetTypeTBAAInfo);<br>
+ if (TBAAInfo)<br>
+ *TBAAInfo = CGM.mergeTBAAInfoForCast(*<wbr>TBAAInfo,<br>
+ TargetTypeTBAAInfo);<br>
+ // If the source l-value is opaque, honor the alignment of the<br>
+ // casted-to type.<br>
+ if (InnerBaseInfo.<wbr>getAlignmentSource() != AlignmentSource::Decl) {<br>
+ if (BaseInfo)<br>
+ BaseInfo->mergeForCast(<wbr>TargetTypeBaseInfo);<br>
+ Addr = Address(Addr.getPointer(), Align);<br>
+ }<br>
}<br>
<br>
if (SanOpts.has(SanitizerKind::<wbr>CFIUnrelatedCast) &&<br>
@@ -969,12 +980,13 @@ Address CodeGenFunction::<wbr>EmitPointerWith<br>
<br>
// Array-to-pointer decay.<br>
case CK_ArrayToPointerDecay:<br>
- return EmitArrayToPointerDecay(CE-><wbr>getSubExpr(), BaseInfo);<br>
+ return EmitArrayToPointerDecay(CE-><wbr>getSubExpr(), BaseInfo, TBAAInfo);<br>
<br>
// Derived-to-base conversions.<br>
case CK_UncheckedDerivedToBase:<br>
case CK_DerivedToBase: {<br>
- Address Addr = EmitPointerWithAlignment(CE-><wbr>getSubExpr(), BaseInfo);<br>
+ Address Addr = EmitPointerWithAlignment(CE-><wbr>getSubExpr(), BaseInfo,<br>
+ TBAAInfo);<br>
auto Derived = CE->getSubExpr()->getType()-><wbr>getPointeeCXXRecordDecl();<br>
return GetAddressOfBaseClass(Addr, Derived,<br>
CE->path_begin(), CE->path_end(),<br>
@@ -994,6 +1006,7 @@ Address CodeGenFunction::<wbr>EmitPointerWith<br>
if (UO->getOpcode() == UO_AddrOf) {<br>
LValue LV = EmitLValue(UO->getSubExpr());<br>
if (BaseInfo) *BaseInfo = LV.getBaseInfo();<br>
+ if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();<br>
return LV.getAddress();<br>
}<br>
}<br>
@@ -1001,7 +1014,8 @@ Address CodeGenFunction::<wbr>EmitPointerWith<br>
// TODO: conditional operators, comma.<br>
<br>
// Otherwise, use the alignment of the type.<br>
- CharUnits Align = getNaturalPointeeTypeAlignment<wbr>(E->getType(), BaseInfo);<br>
+ CharUnits Align = getNaturalPointeeTypeAlignment<wbr>(E->getType(), BaseInfo,<br>
+ TBAAInfo);<br>
return Address(EmitScalarExpr(E), Align);<br>
}<br>
<br>
@@ -2447,8 +2461,10 @@ LValue CodeGenFunction::<wbr>EmitUnaryOpLValu<br>
assert(!T.isNull() && "CodeGenFunction::<wbr>EmitUnaryOpLValue: Illegal type");<br>
<br>
LValueBaseInfo BaseInfo;<br>
- Address Addr = EmitPointerWithAlignment(E-><wbr>getSubExpr(), &BaseInfo);<br>
- LValue LV = MakeAddrLValue(Addr, T, BaseInfo, CGM.getTBAAAccessInfo(T));<br>
+ TBAAAccessInfo TBAAInfo;<br>
+ Address Addr = EmitPointerWithAlignment(E-><wbr>getSubExpr(), &BaseInfo,<br>
+ &TBAAInfo);<br>
+ LValue LV = MakeAddrLValue(Addr, T, BaseInfo, TBAAInfo);<br>
LV.getQuals().setAddressSpace(<wbr>ExprTy.getAddressSpace());<br>
<br>
// We should not generate __weak write barrier on indirect reference<br>
@@ -3048,7 +3064,8 @@ llvm::CallInst *CodeGenFunction::EmitTra<br>
}<br>
<br>
Address CodeGenFunction::<wbr>EmitArrayToPointerDecay(const Expr *E,<br>
- LValueBaseInfo *BaseInfo) {<br>
+ LValueBaseInfo *BaseInfo,<br>
+ TBAAAccessInfo *TBAAInfo) {<br>
assert(E->getType()-><wbr>isArrayType() &&<br>
"Array to pointer decay must have array source type!");<br>
<br>
@@ -3056,6 +3073,7 @@ Address CodeGenFunction::<wbr>EmitArrayToPoin<br>
LValue LV = EmitLValue(E);<br>
Address Addr = LV.getAddress();<br>
if (BaseInfo) *BaseInfo = LV.getBaseInfo();<br>
+ if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();<br>
<br>
// If the array type was an incomplete type, we need to make sure<br>
// the decay ends up being the right type.<br>
@@ -3216,13 +3234,14 @@ LValue CodeGenFunction::<wbr>EmitArraySubscri<br>
}<br>
<br>
LValueBaseInfo BaseInfo;<br>
+ TBAAAccessInfo TBAAInfo;<br>
Address Addr = Address::invalid();<br>
if (const VariableArrayType *vla =<br>
getContext().<wbr>getAsVariableArrayType(E-><wbr>getType())) {<br>
// The base must be a pointer, which is not an aggregate. Emit<br>
// it. It needs to be emitted first in case it's what captures<br>
// the VLA bounds.<br>
- Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo);<br>
+ Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo, &TBAAInfo);<br>
auto *Idx = EmitIdxAfterBase(/*Promote*/<wbr>true);<br>
<br>
// The element count here is the total number of non-VLA elements.<br>
@@ -3246,7 +3265,7 @@ LValue CodeGenFunction::<wbr>EmitArraySubscri<br>
// Indexing over an interface, as in "NSString *P; P[4];"<br>
<br>
// Emit the base pointer.<br>
- Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo);<br>
+ Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo, &TBAAInfo);<br>
auto *Idx = EmitIdxAfterBase(/*Promote*/<wbr>true);<br>
<br>
CharUnits InterfaceSize = getContext().<wbr>getTypeSizeInChars(OIT);<br>
@@ -3294,19 +3313,17 @@ LValue CodeGenFunction::<wbr>EmitArraySubscri<br>
E->getType(), !getLangOpts().<wbr>isSignedOverflowDefined(), SignedIndices,<br>
E->getExprLoc());<br>
BaseInfo = ArrayLV.getBaseInfo();<br>
+ TBAAInfo = CGM.getTBAAAccessInfo(E-><wbr>getType());<br>
} else {<br>
// The base must be a pointer; emit it with an estimate of its alignment.<br>
- Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo);<br>
+ Addr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo, &TBAAInfo);<br>
auto *Idx = EmitIdxAfterBase(/*Promote*/<wbr>true);<br>
Addr = emitArraySubscriptGEP(*this, Addr, Idx, E->getType(),<br>
!getLangOpts().<wbr>isSignedOverflowDefined(),<br>
SignedIndices, E->getExprLoc());<br>
}<br>
<br>
- LValue LV = MakeAddrLValue(Addr, E->getType(), BaseInfo,<br>
- CGM.getTBAAAccessInfo(E-><wbr>getType()));<br>
-<br>
- // TODO: Preserve/extend path TBAA metadata?<br>
+ LValue LV = MakeAddrLValue(Addr, E->getType(), BaseInfo, TBAAInfo);<br>
<br>
if (getLangOpts().ObjC1 &&<br>
getLangOpts().getGC() != LangOptions::NonGC) {<br>
@@ -3321,8 +3338,6 @@ static Address emitOMPArraySectionBase(C<br>
TBAAAccessInfo &TBAAInfo,<br>
QualType BaseTy, QualType ElTy,<br>
bool IsLowerBound) {<br>
- TBAAInfo = CGF.CGM.getTBAAAccessInfo(<wbr>ElTy);<br>
-<br>
LValue BaseLVal;<br>
if (auto *ASE = dyn_cast<OMPArraySectionExpr>(<wbr>Base->IgnoreParenImpCasts())) {<br>
BaseLVal = CGF.EmitOMPArraySectionExpr(<wbr>ASE, IsLowerBound);<br>
@@ -3352,7 +3367,7 @@ static Address emitOMPArraySectionBase(C<br>
BaseInfo.mergeForCast(<wbr>TypeInfo);<br>
return Address(CGF.Builder.<wbr>CreateLoad(BaseLVal.<wbr>getAddress()), Align);<br>
}<br>
- return CGF.EmitPointerWithAlignment(<wbr>Base, &BaseInfo);<br>
+ return CGF.EmitPointerWithAlignment(<wbr>Base, &BaseInfo, &TBAAInfo);<br>
}<br>
<br>
LValue CodeGenFunction::<wbr>EmitOMPArraySectionExpr(const OMPArraySectionExpr *E,<br>
@@ -3518,10 +3533,10 @@ EmitExtVectorElementExpr(const ExtVector<br>
// If it is a pointer to a vector, emit the address and form an lvalue with<br>
// it.<br>
LValueBaseInfo BaseInfo;<br>
- Address Ptr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo);<br>
+ TBAAAccessInfo TBAAInfo;<br>
+ Address Ptr = EmitPointerWithAlignment(E-><wbr>getBase(), &BaseInfo, &TBAAInfo);<br>
const PointerType *PT = E->getBase()->getType()-><wbr>getAs<PointerType>();<br>
- Base = MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo,<br>
- CGM.getTBAAAccessInfo(PT-><wbr>getPointeeType()));<br>
+ Base = MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo, TBAAInfo);<br>
Base.getQuals().<wbr>removeObjCGCAttr();<br>
} else if (E->getBase()->isGLValue()) {<br>
// Otherwise, if the base is an lvalue ( as in the case of foo.x.x),<br>
@@ -3577,7 +3592,8 @@ LValue CodeGenFunction::<wbr>EmitMemberExpr(c<br>
LValue BaseLV;<br>
if (E->isArrow()) {<br>
LValueBaseInfo BaseInfo;<br>
- Address Addr = EmitPointerWithAlignment(<wbr>BaseExpr, &BaseInfo);<br>
+ TBAAAccessInfo TBAAInfo;<br>
+ Address Addr = EmitPointerWithAlignment(<wbr>BaseExpr, &BaseInfo, &TBAAInfo);<br>
QualType PtrTy = BaseExpr->getType()-><wbr>getPointeeType();<br>
SanitizerSet SkippedChecks;<br>
bool IsBaseCXXThis = IsWrappedCXXThis(BaseExpr);<br>
@@ -3587,8 +3603,7 @@ LValue CodeGenFunction::<wbr>EmitMemberExpr(c<br>
SkippedChecks.set(<wbr>SanitizerKind::Null, true);<br>
EmitTypeCheck(TCK_<wbr>MemberAccess, E->getExprLoc(), Addr.getPointer(), PtrTy,<br>
/*Alignment=*/CharUnits::Zero(<wbr>), SkippedChecks);<br>
- BaseLV = MakeAddrLValue(Addr, PtrTy, BaseInfo,<br>
- CGM.getTBAAAccessInfo(PtrTy));<br>
+ BaseLV = MakeAddrLValue(Addr, PtrTy, BaseInfo, TBAAInfo);<br>
} else<br>
BaseLV = EmitCheckedLValue(BaseExpr, TCK_MemberAccess);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.cpp?rev=<wbr>315984&r1=315983&r2=315984&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.cpp Tue Oct 17 02:12:13 2017<br>
@@ -118,9 +118,9 @@ CodeGenFunction::~<wbr>CodeGenFunction() {<br>
}<br>
<br>
CharUnits CodeGenFunction::<wbr>getNaturalPointeeTypeAlignment<wbr>(QualType T,<br>
- LValueBaseInfo *BaseInfo) {<br>
- return getNaturalTypeAlignment(T-><wbr>getPointeeType(), BaseInfo,<br>
- /* TBAAInfo= */ nullptr,<br>
+ LValueBaseInfo *BaseInfo,<br>
+ TBAAAccessInfo *TBAAInfo) {<br>
+ return getNaturalTypeAlignment(T-><wbr>getPointeeType(), BaseInfo, TBAAInfo,<br>
/* forPointeeType= */ true);<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h?rev=315984&<wbr>r1=315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h Tue Oct 17 02:12:13 2017<br>
@@ -1949,7 +1949,8 @@ public:<br>
TBAAAccessInfo *TBAAInfo = nullptr,<br>
bool forPointeeType = false);<br>
CharUnits getNaturalPointeeTypeAlignment<wbr>(QualType T,<br>
- LValueBaseInfo *BaseInfo = nullptr);<br>
+ LValueBaseInfo *BaseInfo = nullptr,<br>
+ TBAAAccessInfo *TBAAInfo = nullptr);<br>
<br>
Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,<br>
LValueBaseInfo *BaseInfo = nullptr,<br>
@@ -3198,7 +3199,8 @@ public:<br>
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);<br>
<br>
Address EmitArrayToPointerDecay(const Expr *Array,<br>
- LValueBaseInfo *BaseInfo = nullptr);<br>
+ LValueBaseInfo *BaseInfo = nullptr,<br>
+ TBAAAccessInfo *TBAAInfo = nullptr);<br>
<br>
class ConstantEmission {<br>
llvm::PointerIntPair<llvm::<wbr>Constant*, 1, bool> ValueAndIsReference;<br>
@@ -3920,7 +3922,8 @@ public:<br>
/// reasonable to just ignore the returned alignment when it isn't from an<br>
/// explicit source.<br>
Address EmitPointerWithAlignment(const Expr *Addr,<br>
- LValueBaseInfo *BaseInfo = nullptr);<br>
+ LValueBaseInfo *BaseInfo = nullptr,<br>
+ TBAAAccessInfo *TBAAInfo = nullptr);<br>
<br>
void EmitSanitizerStatReport(llvm::<wbr>SanitizerStatKind SSK);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp?rev=315984&<wbr>r1=315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp Tue Oct 17 02:12:13 2017<br>
@@ -612,6 +612,13 @@ TBAAAccessInfo CodeGenModule::getTBAAMay<br>
return TBAA->getMayAliasAccessInfo();<br>
}<br>
<br>
+TBAAAccessInfo CodeGenModule::<wbr>mergeTBAAInfoForCast(<wbr>TBAAAccessInfo SourceInfo,<br>
+ TBAAAccessInfo TargetInfo) {<br>
+ if (!TBAA)<br>
+ return TBAAAccessInfo();<br>
+ return TBAA->mergeTBAAInfoForCast(<wbr>SourceInfo, TargetInfo);<br>
+}<br>
+<br>
void CodeGenModule::<wbr>DecorateInstructionWithTBAA(<wbr>llvm::Instruction *Inst,<br>
TBAAAccessInfo TBAAInfo) {<br>
if (llvm::MDNode *Tag = getTBAAAccessTagInfo(TBAAInfo)<wbr>)<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.h?rev=315984&r1=<wbr>315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.h (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.h Tue Oct 17 02:12:13 2017<br>
@@ -677,6 +677,11 @@ public:<br>
/// may-alias accesses.<br>
TBAAAccessInfo getTBAAMayAliasAccessInfo();<br>
<br>
+ /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of<br>
+ /// type casts.<br>
+ TBAAAccessInfo mergeTBAAInfoForCast(<wbr>TBAAAccessInfo SourceInfo,<br>
+ TBAAAccessInfo TargetInfo);<br>
+<br>
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);<br>
<br>
bool isPaddedAtomicType(QualType type);<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.cpp?rev=315984&r1=<wbr>315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.cpp Tue Oct 17 02:12:13 2017<br>
@@ -309,3 +309,11 @@ llvm::MDNode *CodeGenTBAA::getAccessTagI<br>
TBAAAccessInfo CodeGenTBAA::<wbr>getMayAliasAccessInfo() {<br>
return TBAAAccessInfo(getChar());<br>
}<br>
+<br>
+TBAAAccessInfo CodeGenTBAA::<wbr>mergeTBAAInfoForCast(<wbr>TBAAAccessInfo SourceInfo,<br>
+ TBAAAccessInfo TargetInfo) {<br>
+ TBAAAccessInfo MayAliasInfo = getMayAliasAccessInfo();<br>
+ if (SourceInfo == MayAliasInfo || TargetInfo == MayAliasInfo)<br>
+ return MayAliasInfo;<br>
+ return TargetInfo;<br>
+}<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.h?rev=315984&r1=315983&r2=315984&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.h?rev=315984&r1=<wbr>315983&r2=315984&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.h (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenTBAA.h Tue Oct 17 02:12:13 2017<br>
@@ -47,6 +47,12 @@ struct TBAAAccessInfo {<br>
: TBAAAccessInfo(/* AccessType= */ nullptr)<br>
{}<br>
<br>
+ bool operator==(const TBAAAccessInfo &Other) const {<br>
+ return BaseType == Other.BaseType &&<br>
+ AccessType == Other.AccessType &&<br>
+ Offset == Other.Offset;<br>
+ }<br>
+<br>
/// BaseType - The base/leading access type. May be null if this access<br>
/// descriptor represents an access that is not considered to be an access<br>
/// to an aggregate or union member.<br>
@@ -136,6 +142,11 @@ public:<br>
/// getMayAliasAccessInfo - Get TBAA information that represents may-alias<br>
/// accesses.<br>
TBAAAccessInfo getMayAliasAccessInfo();<br>
+<br>
+ /// mergeTBAAInfoForCast - Get merged TBAA information for the purpose of<br>
+ /// type casts.<br>
+ TBAAAccessInfo mergeTBAAInfoForCast(<wbr>TBAAAccessInfo SourceInfo,<br>
+ TBAAAccessInfo TargetInfo);<br>
};<br>
<br>
} // end namespace CodeGen<br>
<br>
Added: cfe/trunk/test/CodeGen/tbaa-<wbr>cast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-cast.cpp?rev=315984&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGen/tbaa-cast.cpp?rev=<wbr>315984&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGen/tbaa-<wbr>cast.cpp (added)<br>
+++ cfe/trunk/test/CodeGen/tbaa-<wbr>cast.cpp Tue Oct 17 02:12:13 2017<br>
@@ -0,0 +1,23 @@<br>
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \<br>
+// RUN: -emit-llvm -o - | FileCheck %s<br>
+//<br>
+// Check that we generate correct TBAA information for lvalues constructed<br>
+// with use of casts.<br>
+<br>
+struct V {<br>
+ unsigned n;<br>
+};<br>
+<br>
+struct S {<br>
+ char bytes[4];<br>
+};<br>
+<br>
+void foo(S *p) {<br>
+// CHECK-LABEL: _Z3fooP1S<br>
+// CHECK: store i32 5, {{.*}}, !tbaa [[TAG_V_n:!.*]]<br>
+ ((V*)p->bytes)->n = 5;<br>
+}<br>
+<br>
+// CHECK-DAG: [[TAG_V_n]] = !{[[TYPE_V:!.*]], [[TYPE_int:!.*]], i64 0}<br>
+// CHECK-DAG: [[TYPE_V]] = !{!"_ZTS1V", !{{.*}}, i64 0}<br>
+// CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>