[cfe-commits] r71080 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/xfail-no-outofbounds.c

Eli Friedman eli.friedman at gmail.com
Wed May 6 09:19:50 PDT 2009


On Wed, May 6, 2009 at 4:51 AM, Zhongxing Xu <xuzhongxing at gmail.com> wrote:
> +// getTypeWidth - compute the width of the type. Should pass in
> +// canonical type.
> +static unsigned getTypeWidth(ASTContext& Ctx, QualType T) {
> +  TargetInfo& Target = Ctx.getTargetInfo();
> +  QualType CanT = Ctx.getCanonicalType(T);
> +
> +  if (CanT->isPointerType())
> +    return Target.getPointerWidth(0);
> +
> +  if (CanT->isCharType())
> +    return Target.getCharWidth();
> +
> +  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanT)) {
> +    switch (BT->getKind()) {
> +    case BuiltinType::Char_U:
> +    case BuiltinType::UChar:
> +    case BuiltinType::Char_S:
> +    case BuiltinType::SChar:
> +      return Target.getCharWidth();
> +
> +    case BuiltinType::UShort:
> +    case BuiltinType::Short:
> +      return Target.getShortWidth();
> +
> +    case BuiltinType::UInt:
> +    case BuiltinType::Int:
> +      return Target.getIntWidth();
> +
> +    case BuiltinType::ULong:
> +    case BuiltinType::Long:
> +      return Target.getLongWidth();
> +    default:
> +      assert(0 && "Unprocessed builtin type.");
> +    }
> +  }
> +
> +  assert(0 && "Unprocessed type.");
> +}

Why not just use ASTContext::getTypeSize()?

-Eli




More information about the cfe-commits mailing list