]> granicus.if.org Git - clang/commitdiff
Refine __builtin_object_size. Don't try and get a size for things
authorMike Stump <mrs@apple.com>
Wed, 28 Oct 2009 21:22:24 +0000 (21:22 +0000)
committerMike Stump <mrs@apple.com>
Wed, 28 Oct 2009 21:22:24 +0000 (21:22 +0000)
that don't have sizes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85435 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp

index dc53289165aae5416177fd7a835cf7fc63dad2d9..a4ca2c4db6766e633362944abb984c253090e973 100644 (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);
+            }
           }
         }