Revert 289252 (and follow-up 289285), it caused PR31374
llvm-svn: 289713
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c57b782..5dd493c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1088,7 +1088,6 @@
unsigned InvalidBase : 1;
unsigned CallIndex : 31;
SubobjectDesignator Designator;
- bool IsNullPtr;
const APValue::LValueBase getLValueBase() const { return Base; }
CharUnits &getLValueOffset() { return Offset; }
@@ -1096,15 +1095,13 @@
unsigned getLValueCallIndex() const { return CallIndex; }
SubobjectDesignator &getLValueDesignator() { return Designator; }
const SubobjectDesignator &getLValueDesignator() const { return Designator;}
- bool isNullPointer() const { return IsNullPtr;}
void moveInto(APValue &V) const {
if (Designator.Invalid)
- V = APValue(Base, Offset, APValue::NoLValuePath(), CallIndex,
- IsNullPtr);
+ V = APValue(Base, Offset, APValue::NoLValuePath(), CallIndex);
else
V = APValue(Base, Offset, Designator.Entries,
- Designator.IsOnePastTheEnd, CallIndex, IsNullPtr);
+ Designator.IsOnePastTheEnd, CallIndex);
}
void setFrom(ASTContext &Ctx, const APValue &V) {
assert(V.isLValue());
@@ -1113,17 +1110,14 @@
InvalidBase = false;
CallIndex = V.getLValueCallIndex();
Designator = SubobjectDesignator(Ctx, V);
- IsNullPtr = V.isNullPointer();
}
- void set(APValue::LValueBase B, unsigned I = 0, bool BInvalid = false,
- bool IsNullPtr_ = false, uint64_t Offset_ = 0) {
+ void set(APValue::LValueBase B, unsigned I = 0, bool BInvalid = false) {
Base = B;
- Offset = CharUnits::fromQuantity(Offset_);
+ Offset = CharUnits::Zero();
InvalidBase = BInvalid;
CallIndex = I;
Designator = SubobjectDesignator(getType(B));
- IsNullPtr = IsNullPtr_;
}
void setInvalid(APValue::LValueBase B, unsigned I = 0) {
@@ -1136,7 +1130,7 @@
CheckSubobjectKind CSK) {
if (Designator.Invalid)
return false;
- if (IsNullPtr) {
+ if (!Base) {
Info.CCEDiag(E, diag::note_constexpr_null_subobject)
<< CSK;
Designator.setInvalid();
@@ -1165,22 +1159,9 @@
if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
Designator.addComplexUnchecked(EltTy, Imag);
}
- void clearIsNullPointer() {
- IsNullPtr = false;
- }
- void adjustOffsetAndIndex(EvalInfo &Info, const Expr *E, uint64_t Index,
- CharUnits ElementSize) {
- // Compute the new offset in the appropriate width.
- Offset += Index * ElementSize;
- if (Index && checkNullPointer(Info, E, CSK_ArrayIndex))
- Designator.adjustIndex(Info, E, Index);
- if (Index)
- clearIsNullPointer();
- }
- void adjustOffset(CharUnits N) {
- Offset += N;
- if (N.getQuantity())
- clearIsNullPointer();
+ void adjustIndex(EvalInfo &Info, const Expr *E, uint64_t N) {
+ if (N && checkNullPointer(Info, E, CSK_ArrayIndex))
+ Designator.adjustIndex(Info, E, N);
}
};
@@ -2055,7 +2036,7 @@
}
unsigned I = FD->getFieldIndex();
- LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I)));
+ LVal.Offset += Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I));
LVal.addDecl(Info, E, FD);
return true;
}
@@ -2109,7 +2090,9 @@
if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee))
return false;
- LVal.adjustOffsetAndIndex(Info, E, Adjustment, SizeOfPointee);
+ // Compute the new offset in the appropriate width.
+ LVal.Offset += Adjustment * SizeOfPointee;
+ LVal.adjustIndex(Info, E, Adjustment);
return true;
}
@@ -5095,9 +5078,7 @@
return true;
}
bool ZeroInitialization(const Expr *E) {
- auto Offset = Info.Ctx.getTargetNullPointerValue(E->getType());
- Result.set((Expr*)nullptr, 0, false, true, Offset);
- return true;
+ return Success((Expr*)nullptr);
}
bool VisitBinaryOperator(const BinaryOperator *E);
@@ -5196,8 +5177,6 @@
else
CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
}
- if (E->getCastKind() == CK_AddressSpaceConversion && Result.IsNullPtr)
- ZeroInitialization(E);
return true;
case CK_DerivedToBase:
@@ -5239,7 +5218,6 @@
Result.Offset = CharUnits::fromQuantity(N);
Result.CallIndex = 0;
Result.Designator.setInvalid();
- Result.IsNullPtr = false;
return true;
} else {
// Cast is of an lvalue, no need to change value.
@@ -8414,13 +8392,8 @@
return true;
}
- uint64_t V;
- if (LV.isNullPointer())
- V = Info.Ctx.getTargetNullPointerValue(SrcType);
- else
- V = LV.getLValueOffset().getQuantity();
-
- APSInt AsInt = Info.Ctx.MakeIntValue(V, SrcType);
+ APSInt AsInt = Info.Ctx.MakeIntValue(LV.getLValueOffset().getQuantity(),
+ SrcType);
return Success(HandleIntToIntCast(Info, E, DestType, SrcType, AsInt), E);
}