diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-03-24 14:43:42 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-03-24 14:43:42 +0000 |
commit | 88a569a9781e0472a1f1c392f6c94ed0c068d946 (patch) | |
tree | 8db63217e09c61531564feeb57aba541503fcc8c /lib | |
parent | d961ea91e14fdf4047db3e891def9951ee7afde1 (diff) |
Revert r153360 (and r153380), "Second part of PR12251. Produce the range metadata in clang for booleans and".
For i686 targets (eg. cygwin), I saw "Range must not be empty!" in verifier.
It produces (i32)[0x80000000:0x80000000) from (uint64_t)[0xFFFFFFFF80000000ULL:0x0000000080000000ULL), for signed i32 on MDNode::Range.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153382 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 69 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 1 |
2 files changed, 8 insertions, 62 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 5a847a3b96..30e3e7ad2c 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -860,61 +860,6 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue) { 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); - - llvm::LLVMContext &C = getLLVMContext(); - llvm::MDNode *Range = llvm::MDNode::get(C, LowAndHigh); - return Range; -} - llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, unsigned Alignment, QualType Ty, llvm::MDNode *TBAAInfo) { @@ -929,16 +874,18 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, if (Ty->isAtomicType()) Load->setAtomic(llvm::SequentiallyConsistent); - if (CGM.getCodeGenOpts().OptimizationLevel > 0) - if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty)) - Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo); - return EmitFromMemory(Load, Ty); } +static bool isBooleanUnderlyingType(QualType Ty) { + if (const EnumType *ET = dyn_cast<EnumType>(Ty)) + return ET->getDecl()->getIntegerType()->isBooleanType(); + return false; +} + llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) { // Bool has a different representation in memory than in registers. - if (hasBooleanRepresentation(Ty)) { + if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) { // This should really always be an i1, but sometimes it's already // an i8, and it's awkward to track those cases down. if (Value->getType()->isIntegerTy(1)) @@ -951,7 +898,7 @@ llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) { llvm::Value *CodeGenFunction::EmitFromMemory(llvm::Value *Value, QualType Ty) { // Bool has a different representation in memory than in registers. - if (hasBooleanRepresentation(Ty)) { + if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) { assert(Value->getType()->isIntegerTy(8) && "memory rep of bool not i8"); return Builder.CreateTrunc(Value, Builder.getInt1Ty(), "tobool"); } diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 85cbd143d8..e0e6501b19 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2522,7 +2522,6 @@ public: unsigned AccuracyD = 1); private: - llvm::MDNode *getRangeForLoadFromType(QualType Ty); void EmitReturnOfRValue(RValue RV, QualType Ty); /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |