summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-09 23:32:34 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-09 23:32:34 +0000
commitb511603281a394c74c6cfcd33835c18d8f57649c (patch)
tree98529bfb5ac7e52b23e4a2f277fbe15aeb4c29ce /clang/lib/AST/ExprConstant.cpp
parenta97c4d2154c6bd40ece4742cef7e5b95d173429c (diff)
downloadbcm5719-llvm-b511603281a394c74c6cfcd33835c18d8f57649c.tar.gz
bcm5719-llvm-b511603281a394c74c6cfcd33835c18d8f57649c.zip
AST: Don't assume two zero sized objects live at different addresses
Zero sized objects may overlap with each other or any other object. This fixes PR21786. llvm-svn: 223852
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 28913385f05..acf78efad66 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1422,6 +1422,12 @@ static bool IsWeakLValue(const LValue &Value) {
return Decl && Decl->isWeak();
}
+static bool isZeroSized(const LValue &Value) {
+ const ValueDecl *Decl = GetLValueBaseDecl(Value);
+ return Decl && isa<VarDecl>(Decl) &&
+ Decl->getASTContext().getTypeSize(Decl->getType()) == 0;
+}
+
static bool EvalPointerValueAsBool(const APValue &Value, bool &Result) {
// A null base expression indicates a null pointer. These are always
// evaluatable, and they are false unless the offset is zero.
@@ -6979,6 +6985,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
(RHSValue.Base && RHSValue.Offset.isZero() &&
isOnePastTheEndOfCompleteObject(Info.Ctx, LHSValue)))
return Error(E);
+ // We can't tell whether an object is at the same address as another
+ // zero sized object.
+ if (isZeroSized(LHSValue) || isZeroSized(RHSValue))
+ return Error(E);
// Pointers with different bases cannot represent the same object.
// (Note that clang defaults to -fmerge-all-constants, which can
// lead to inconsistent results for comparisons involving the address
OpenPOWER on IntegriCloud