summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2014-09-22 17:11:59 +0000
committerFariborz Jahanian <fjahanian@apple.com>2014-09-22 17:11:59 +0000
commita3d8879be7344cfcfa766aab072cbb9330ab7604 (patch)
treed5ceb5bf0e0934f89ecccd8d689aa3f371526dbd /clang/lib/AST
parent9f73851e396bc3ee4c7536e3eb1d93c06c8148c5 (diff)
downloadbcm5719-llvm-a3d8879be7344cfcfa766aab072cbb9330ab7604.tar.gz
bcm5719-llvm-a3d8879be7344cfcfa766aab072cbb9330ab7604.zip
Fix evatuated value of __builtin_object_size according to its
'type' argument when it cannot be determined which objects ptr points to at compile time. rdar://18334276 llvm-svn: 218258
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/ExprConstant.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 743e59f19a6..0bd45dac644 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6052,8 +6052,20 @@ bool IntExprEvaluator::TryEvaluateBuiltinObjectSize(const CallExpr *E) {
return false;
}
- // If we can prove the base is null, lower to zero now.
- if (!Base.getLValueBase()) return Success(0, E);
+ if (!Base.getLValueBase()) {
+ // It is not possible to determine which objects ptr points to at compile time,
+ // __builtin_object_size should return (size_t) -1 for type 0 or 1
+ // and (size_t) 0 for type 2 or 3.
+ llvm::APSInt TypeIntVaue;
+ const Expr *ExprType = E->getArg(1);
+ if (!ExprType->EvaluateAsInt(TypeIntVaue, Info.Ctx))
+ return false;
+ if (TypeIntVaue == 0 || TypeIntVaue == 1)
+ return Success(-1, E);
+ if (TypeIntVaue == 2 || TypeIntVaue == 3)
+ return Success(0, E);
+ return Error(E);
+ }
QualType T = GetObjectType(Base.getLValueBase());
if (T.isNull() ||
OpenPOWER on IntegriCloud