diff options
Diffstat (limited to 'lib/AST')
-rw-r--r-- | lib/AST/ASTContext.cpp | 2 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 9 | ||||
-rw-r--r-- | lib/AST/ExprConstant.cpp | 31 | ||||
-rw-r--r-- | lib/AST/Type.cpp | 11 |
4 files changed, 34 insertions, 19 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index bb27ab9747..fbf26ccca5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3201,7 +3201,7 @@ CharUnits ASTContext::getObjCEncodingTypeSize(QualType type) { CharUnits sz = getTypeSizeInChars(type); // Make all integer and enum types at least as large as an int - if (sz.isPositive() && type->isIntegralType()) + if (sz.isPositive() && type->isIntegralOrEnumerationType()) sz = std::max(sz, getTypeSizeInChars(IntTy)); // Treat arrays as pointers, since that's how they're passed in. else if (type->isArrayType()) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 68fcb35c79..db2473bb55 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -37,7 +37,7 @@ bool Expr::isKnownToHaveBooleanValue() const { // If this value has _Bool type, it is obvious 0/1. if (getType()->isBooleanType()) return true; // If this is a non-scalar-integer type, we don't care enough to try. - if (!getType()->isIntegralType()) return false; + if (!getType()->isIntegralOrEnumerationType()) return false; if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) return PE->getSubExpr()->isKnownToHaveBooleanValue(); @@ -160,7 +160,7 @@ void DeclRefExpr::computeDependence() { // (VD) - a constant with integral or enumeration type and is // initialized with an expression that is value-dependent. else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { - if (Var->getType()->isIntegralType() && + if (Var->getType()->isIntegralOrEnumerationType() && Var->getType().getCVRQualifiers() == Qualifiers::Const) { if (const Expr *Init = Var->getAnyInitializer()) if (Init->isValueDependent()) @@ -1598,7 +1598,7 @@ Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { if (CastExpr *P = dyn_cast<CastExpr>(E)) { // We ignore integer <-> casts that are of the same width, ptr<->ptr and - // ptr<->int casts of the same width. We also ignore all identify casts. + // ptr<->int casts of the same width. We also ignore all identity casts. Expr *SE = P->getSubExpr(); if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { @@ -1797,7 +1797,8 @@ bool Expr::isNullPointerConstant(ASTContext &Ctx, // If the unthinkable happens, fall through to the safest alternative. case NPC_ValueDependentIsNull: - return isTypeDependent() || getType()->isIntegralType(); + return isTypeDependent() || + (getType()->isIntegralType() && !getType()->isEnumeralType()); case NPC_ValueDependentIsNotNull: return false; diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index d97d625616..bec3792000 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -157,7 +157,7 @@ static bool EvalPointerValueAsBool(LValue& Value, bool& Result) { static bool HandleConversionToBool(const Expr* E, bool& Result, EvalInfo &Info) { - if (E->getType()->isIntegralType()) { + if (E->getType()->isIntegralOrEnumerationType()) { APSInt IntResult; if (!EvaluateInteger(E, IntResult, Info)) return false; @@ -542,7 +542,7 @@ bool PointerExprEvaluator::VisitCastExpr(CastExpr* E) { SubExpr->getType()->isBlockPointerType()) return Visit(SubExpr); - if (SubExpr->getType()->isIntegralType()) { + if (SubExpr->getType()->isIntegralOrEnumerationType()) { APValue Value; if (!EvaluateIntegerOrLValue(SubExpr, Value, Info)) break; @@ -839,7 +839,8 @@ public: : Info(info), Result(result) {} bool Success(const llvm::APSInt &SI, const Expr *E) { - assert(E->getType()->isIntegralType() && "Invalid evaluation result."); + assert(E->getType()->isIntegralOrEnumerationType() && + "Invalid evaluation result."); assert(SI.isSigned() == E->getType()->isSignedIntegerType() && "Invalid evaluation result."); assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && @@ -849,7 +850,8 @@ public: } bool Success(const llvm::APInt &I, const Expr *E) { - assert(E->getType()->isIntegralType() && "Invalid evaluation result."); + assert(E->getType()->isIntegralOrEnumerationType() && + "Invalid evaluation result."); assert(I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && "Invalid evaluation result."); Result = APValue(APSInt(I)); @@ -858,7 +860,8 @@ public: } bool Success(uint64_t Value, const Expr *E) { - assert(E->getType()->isIntegralType() && "Invalid evaluation result."); + assert(E->getType()->isIntegralOrEnumerationType() && + "Invalid evaluation result."); Result = APValue(Info.Ctx.MakeIntValue(Value, E->getType())); return true; } @@ -964,12 +967,12 @@ private: } // end anonymous namespace static bool EvaluateIntegerOrLValue(const Expr* E, APValue &Result, EvalInfo &Info) { - assert(E->getType()->isIntegralType()); + assert(E->getType()->isIntegralOrEnumerationType()); return IntExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E)); } static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) { - assert(E->getType()->isIntegralType()); + assert(E->getType()->isIntegralOrEnumerationType()); APValue Val; if (!EvaluateIntegerOrLValue(E, Val, Info) || !Val.isInt()) @@ -1335,8 +1338,8 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { return Success(Result, E); } } - if (!LHSTy->isIntegralType() || - !RHSTy->isIntegralType()) { + if (!LHSTy->isIntegralOrEnumerationType() || + !RHSTy->isIntegralOrEnumerationType()) { // We can't continue from here for non-integral types, and they // could potentially confuse the following operations. return false; @@ -1591,7 +1594,7 @@ bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) { } // Only handle integral operations... - if (!E->getSubExpr()->getType()->isIntegralType()) + if (!E->getSubExpr()->getType()->isIntegralOrEnumerationType()) return false; // Get the operand value into 'Result'. @@ -1634,7 +1637,7 @@ bool IntExprEvaluator::VisitCastExpr(CastExpr *E) { } // Handle simple integer->integer casts. - if (SrcType->isIntegralType()) { + if (SrcType->isIntegralOrEnumerationType()) { if (!Visit(SubExpr)) return false; @@ -1929,7 +1932,7 @@ bool FloatExprEvaluator::VisitFloatingLiteral(const FloatingLiteral *E) { bool FloatExprEvaluator::VisitCastExpr(CastExpr *E) { Expr* SubExpr = E->getSubExpr(); - if (SubExpr->getType()->isIntegralType()) { + if (SubExpr->getType()->isIntegralOrEnumerationType()) { APSInt IntResult; if (!EvaluateInteger(SubExpr, IntResult, Info)) return false; @@ -2337,7 +2340,7 @@ static ICEDiag CheckEvalInICE(const Expr* E, ASTContext &Ctx) { static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { assert(!E->isValueDependent() && "Should not see value dependent exprs!"); - if (!E->getType()->isIntegralType()) { + if (!E->getType()->isIntegralOrEnumerationType()) { return ICEDiag(2, E->getLocStart()); } @@ -2600,7 +2603,7 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case Expr::CXXReinterpretCastExprClass: case Expr::CXXConstCastExprClass: { const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr(); - if (SubExpr->getType()->isIntegralType()) + if (SubExpr->getType()->isIntegralOrEnumerationType()) return CheckICE(SubExpr, Ctx); if (isa<FloatingLiteral>(SubExpr->IgnoreParens())) return NoDiag(); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 1d91e76c8f..92fffd1881 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -450,6 +450,17 @@ bool Type::isIntegralType() const { return false; } +bool Type::isIntegralOrEnumerationType() const { + if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) + return BT->getKind() >= BuiltinType::Bool && + BT->getKind() <= BuiltinType::Int128; + + if (isa<EnumType>(CanonicalType)) + return true; + + return false; +} + bool Type::isEnumeralType() const { if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) return TT->getDecl()->isEnum(); |