]> granicus.if.org Git - clang/commitdiff
Fixed another case where sizeof() returns the size in bytes, not bits.
authorTed Kremenek <kremenek@apple.com>
Mon, 17 Dec 2007 17:38:43 +0000 (17:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 17 Dec 2007 17:38:43 +0000 (17:38 +0000)
This parallels a previous patch (duplicate logic caused the bug to appear
in multiple locations):

  r44316 (http://llvm.org/viewvc/llvm-project?rev=44316&view=rev).

Patch provided by Nuno Lopes.

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

AST/Expr.cpp

index 9747c470806780ba0b3c78b5258a366e750b5317..f4f89001f2bda65dcc32c2356025f094a4497bc0 100644 (file)
@@ -662,10 +662,16 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
     
     // Get information about the size or align.
-    if (Exp->isSizeOf())
-      Result = Ctx.getTypeSize(Exp->getArgumentType(), Exp->getOperatorLoc());
+    if (Exp->isSizeOf()) {
+      unsigned CharSize =
+        Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
+      
+      Result = Ctx.getTypeSize(Exp->getArgumentType(),
+                               Exp->getOperatorLoc()) / CharSize;
+    }
     else
       Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc());
+    
     break;
   }
   case BinaryOperatorClass: {