Refine __builtin_object_size. Don't try and get a size for things

that don't have sizes.

llvm-svn: 85435
This commit is contained in:
Mike Stump 2009-10-28 21:22:24 +00:00
parent 29baa2b1ba
commit 5179f308a2
1 changed files with 12 additions and 7 deletions

View File

@ -943,13 +943,18 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
if (const Expr *LVBase = Base.Val.getLValueBase())
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(LVBase)) {
if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
uint64_t Size = Info.Ctx.getTypeSize(VD->getType()) / 8;
uint64_t Offset = Base.Val.getLValueOffset();
if (Offset <= Size)
Size -= Base.Val.getLValueOffset();
else
Size = 0;
return Success(Size, E);
if (!VD->getType()->isIncompleteType()
&& VD->getType()->isObjectType()
&& !VD->getType()->isVariablyModifiedType()
&& !VD->getType()->isDependentType()) {
uint64_t Size = Info.Ctx.getTypeSize(VD->getType()) / 8;
uint64_t Offset = Base.Val.getLValueOffset();
if (Offset <= Size)
Size -= Base.Val.getLValueOffset();
else
Size = 0;
return Success(Size, E);
}
}
}