summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-08-29 08:32:55 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-08-29 08:32:55 +0000
commitc378ca50439247782a87973bf876676685297854 (patch)
treec9d14f4efc37db70d75a7ca06e8cead6d30754d9 /clang/lib/AST
parente4d0c142e8e9cf8b456c06f5ce9641d89b67ac86 (diff)
downloadbcm5719-llvm-c378ca50439247782a87973bf876676685297854.tar.gz
bcm5719-llvm-c378ca50439247782a87973bf876676685297854.zip
[AST] Don't crash when comparing incomplete object
We cannot tell if an object is past-the-end if its type is incomplete. Zero sized objects satisfy past-the-end criteria and our object might turn out to be such an object. This fixes PR24622. llvm-svn: 246359
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/ExprConstant.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6350ff1d840..8aea10d516e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6602,9 +6602,15 @@ static bool isOnePastTheEndOfCompleteObject(const ASTContext &Ctx,
!LV.getLValueDesignator().isOnePastTheEnd())
return false;
+ // A pointer to an incomplete type might be past-the-end if the type's size is
+ // zero. We cannot tell because the type is incomplete.
+ QualType Ty = getType(LV.getLValueBase());
+ if (Ty->isIncompleteType())
+ return true;
+
// We're a past-the-end pointer if we point to the byte after the object,
// no matter what our type or path is.
- auto Size = Ctx.getTypeSizeInChars(getType(LV.getLValueBase()));
+ auto Size = Ctx.getTypeSizeInChars(Ty);
return LV.getLValueOffset() == Size;
}
OpenPOWER on IntegriCloud