summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2017-05-26 02:16:00 +0000
committerTim Northover <tnorthover@apple.com>2017-05-26 02:16:00 +0000
commit0150333a3c565fec97d4d65302abbb15ed21ecc4 (patch)
tree88f48feb73042fa360b5e1c95f429cc519afbe6d /clang/lib/AST/ExprConstant.cpp
parenteb04c8cae2f0867c3959285a992f5319b8d6cfc7 (diff)
downloadbcm5719-llvm-0150333a3c565fec97d4d65302abbb15ed21ecc4.tar.gz
bcm5719-llvm-0150333a3c565fec97d4d65302abbb15ed21ecc4.zip
Create valid LValue to represent null pointers in constant exprs
We were leaving the SubobjectDesignator in a surprising situation, where it was allegedly valid but didn't actually refer to a type. This caused a crash later on. This patch fills out the SubobjectDesignator with the pointee type (as happens in other evaluations of constant pointers) so that we don't crash later. llvm-svn: 303957
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index bd8b3abd927..c19812e341c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1230,8 +1230,7 @@ namespace {
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) {
#ifndef NDEBUG
// We only allow a few types of invalid bases. Enforce that here.
if (BInvalid) {
@@ -1242,11 +1241,20 @@ namespace {
#endif
Base = B;
- Offset = CharUnits::fromQuantity(Offset_);
+ Offset = CharUnits::fromQuantity(0);
InvalidBase = BInvalid;
CallIndex = I;
Designator = SubobjectDesignator(getType(B));
- IsNullPtr = IsNullPtr_;
+ IsNullPtr = false;
+ }
+
+ void setNull(QualType PointerTy, uint64_t TargetVal) {
+ Base = (Expr *)nullptr;
+ Offset = CharUnits::fromQuantity(TargetVal);
+ InvalidBase = false;
+ CallIndex = 0;
+ Designator = SubobjectDesignator(PointerTy->getPointeeType());
+ IsNullPtr = true;
}
void setInvalid(APValue::LValueBase B, unsigned I = 0) {
@@ -5494,8 +5502,8 @@ public:
return true;
}
bool ZeroInitialization(const Expr *E) {
- auto Offset = Info.Ctx.getTargetNullPointerValue(E->getType());
- Result.set((Expr*)nullptr, 0, false, true, Offset);
+ auto TargetVal = Info.Ctx.getTargetNullPointerValue(E->getType());
+ Result.setNull(E->getType(), TargetVal);
return true;
}
OpenPOWER on IntegriCloud