[cfe-commits] r45098 - /cfe/trunk/AST/Expr.cpp

Ted Kremenek kremenek at apple.com
Mon Dec 17 09:38:44 PST 2007


Author: kremenek
Date: Mon Dec 17 11:38:43 2007
New Revision: 45098

URL: http://llvm.org/viewvc/llvm-project?rev=45098&view=rev
Log:
Fixed another case where sizeof() returns the size in bytes, not bits.
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.

Modified:
    cfe/trunk/AST/Expr.cpp

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45098&r1=45097&r2=45098&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Mon Dec 17 11:38:43 2007
@@ -662,10 +662,16 @@
       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: {





More information about the cfe-commits mailing list