From 5179f308a269f3262757aa311b3987fe67932421 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Wed, 28 Oct 2009 21:22:24 +0000 Subject: [PATCH] Refine __builtin_object_size. Don't try and get a size for things that don't have sizes. llvm-svn: 85435 --- clang/lib/AST/ExprConstant.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index dc53289165aa..a4ca2c4db676 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -943,13 +943,18 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { if (const Expr *LVBase = Base.Val.getLValueBase()) if (const DeclRefExpr *DRE = dyn_cast(LVBase)) { if (const VarDecl *VD = dyn_cast(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); + } } }