summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-11 19:36:24 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-11 19:36:24 +0000
commit27db35878dccd6dd5e62130f644bf01939f56716 (patch)
tree7b310f00f4bafae67049ac67c3ceac85e4a2e471 /clang/lib/AST/ExprConstant.cpp
parent2521f36e5ddcadf8dc4bd9803c4ac74fc276f046 (diff)
downloadbcm5719-llvm-27db35878dccd6dd5e62130f644bf01939f56716.tar.gz
bcm5719-llvm-27db35878dccd6dd5e62130f644bf01939f56716.zip
AST: Incomplete types might be zero sized
Comparing the address of an object with an incomplete type might return true with a 'distinct' object if the former has a size of zero. However, such an object should compare unequal with null. llvm-svn: 224040
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index acf78efad66..417f7931df4 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1424,8 +1424,11 @@ static bool IsWeakLValue(const LValue &Value) {
static bool isZeroSized(const LValue &Value) {
const ValueDecl *Decl = GetLValueBaseDecl(Value);
- return Decl && isa<VarDecl>(Decl) &&
- Decl->getASTContext().getTypeSize(Decl->getType()) == 0;
+ if (Decl && isa<VarDecl>(Decl)) {
+ QualType Ty = Decl->getType();
+ return Ty->isIncompleteType() || Decl->getASTContext().getTypeSize(Ty) == 0;
+ }
+ return false;
}
static bool EvalPointerValueAsBool(const APValue &Value, bool &Result) {
@@ -6987,7 +6990,8 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
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))
+ if ((RHSValue.Base && isZeroSized(LHSValue)) ||
+ (LHSValue.Base && isZeroSized(RHSValue)))
return Error(E);
// Pointers with different bases cannot represent the same object.
// (Note that clang defaults to -fmerge-all-constants, which can
OpenPOWER on IntegriCloud