[cfe-commits] r153360 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/pr12251.c test/CodeGenCXX/pr12251.cpp

NAKAMURA Takumi geek4civic at gmail.com
Sat Mar 24 07:45:47 PDT 2012


2012/3/24 Rafael Espindola <rafael.espindola at gmail.com>:
> Author: rafael
> Date: Fri Mar 23 19:28:06 2012
> New Revision: 153360
>
> URL: http://llvm.org/viewvc/llvm-project?rev=153360&view=rev
> Log:
> Second part of PR12251. Produce the range metadata in clang for booleans and
> c++ enums.
>
> Added:
>    cfe/trunk/test/CodeGen/pr12251.c
>    cfe/trunk/test/CodeGenCXX/pr12251.cpp
> Modified:
>    cfe/trunk/lib/CodeGen/CGExpr.cpp
>    cfe/trunk/lib/CodeGen/CodeGenFunction.h

> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=153360&r1=153359&r2=153360&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Mar 23 19:28:06 2012
> @@ -860,6 +860,61 @@
>                           lvalue.getType(), lvalue.getTBAAInfo());
>  }
>
> +static bool hasBooleanRepresentation(QualType Ty) {
> +  if (Ty->isBooleanType())
> +    return true;
> +
> +  if (const EnumType *ET = Ty->getAs<EnumType>())
> +    return ET->getDecl()->getIntegerType()->isBooleanType();
> +
> +  return false;
> +}
> +
> +llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(QualType Ty) {
> +  const EnumType *ET = Ty->getAs<EnumType>();
> +  bool IsRegularCPlusPlusEnum = getLangOpts().CPlusPlus && ET &&
> +    !ET->getDecl()->isFixed();
> +  bool IsBool = hasBooleanRepresentation(Ty);
> +  llvm::Type *LTy;
> +  if (!IsBool && !IsRegularCPlusPlusEnum)
> +    return NULL;
> +
> +  uint64_t Min;
> +  uint64_t End;
> +  if (IsBool) {
> +    Min = 0;
> +    End = 2;
> +    LTy = Int8Ty;
> +  } else {
> +    const EnumDecl *ED = ET->getDecl();
> +    LTy = ConvertTypeForMem(ED->getIntegerType());
> +    unsigned NumNegativeBits = ED->getNumNegativeBits();
> +    unsigned NumPositiveBits = ED->getNumPositiveBits();
> +
> +    if (NumNegativeBits) {
> +      unsigned NumBits = std::max(NumNegativeBits, NumPositiveBits + 1);
> +      assert(NumBits <= 64);
> +      End = 1ULL << (NumBits - 1);
> +      Min = -End;
> +    } else {
> +      assert(NumPositiveBits <= 64);
> +      if (NumPositiveBits == 64)
> +        return NULL;
> +      End = 1ULL << NumPositiveBits;
> +      Min = 0;
> +    }
> +  }
> +
> +  assert(End != Min);
> +  llvm::Value *LowAndHigh[2];
> +  LowAndHigh[0] = llvm::ConstantInt::get(LTy, Min);
> +  LowAndHigh[1] = llvm::ConstantInt::get(LTy, End);

I don't think it would be safe if LTy is i32. It broke i686-clang.
Excuse me, reverted in r153382.

...Takumi




More information about the cfe-commits mailing list