}
};
- /// A core constant value. This can be the value of any constant expression,
- /// or a pointer or reference to a non-static object or function parameter.
- ///
- /// For an LValue, the base and offset are stored in the APValue subobject,
- /// but the other information is stored in the SubobjectDesignator. For all
- /// other value kinds, the value is stored directly in the APValue subobject.
- class CCValue : public APValue {
- typedef llvm::APSInt APSInt;
- typedef llvm::APFloat APFloat;
- /// If the value is a reference or pointer, this is a description of how the
- /// subobject was specified.
- SubobjectDesignator Designator;
- public:
- struct GlobalValue {};
-
- CCValue() {}
- explicit CCValue(const APSInt &I) : APValue(I) {}
- explicit CCValue(const APFloat &F) : APValue(F) {}
- CCValue(const APValue *E, unsigned N) : APValue(E, N) {}
- CCValue(const APSInt &R, const APSInt &I) : APValue(R, I) {}
- CCValue(const APFloat &R, const APFloat &I) : APValue(R, I) {}
- CCValue(const CCValue &V) : APValue(V), Designator(V.Designator) {}
- CCValue(LValueBase B, const CharUnits &O, unsigned I,
- const SubobjectDesignator &D) :
- APValue(B, O, APValue::NoLValuePath(), I), Designator(D) {}
- CCValue(ASTContext &Ctx, const APValue &V, GlobalValue) :
- APValue(V), Designator(Ctx, V) {
- }
- CCValue(const ValueDecl *D, bool IsDerivedMember,
- ArrayRef<const CXXRecordDecl*> Path) :
- APValue(D, IsDerivedMember, Path) {}
- CCValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr) :
- APValue(LHSExpr, RHSExpr) {}
-
- SubobjectDesignator &getLValueDesignator() {
- assert(getKind() == LValue);
- return Designator;
- }
- const SubobjectDesignator &getLValueDesignator() const {
- return const_cast<CCValue*>(this)->getLValueDesignator();
- }
- APValue toAPValue() const {
- if (!isLValue())
- return *this;
-
- if (Designator.Invalid) {
- // This is not a core constant expression. An appropriate diagnostic
- // will have already been produced.
- return APValue(getLValueBase(), getLValueOffset(),
- APValue::NoLValuePath(), getLValueCallIndex());
- }
-
- return APValue(getLValueBase(), getLValueOffset(),
- Designator.Entries, Designator.IsOnePastTheEnd,
- getLValueCallIndex());
- }
- };
-
/// A stack frame in the constexpr call stack.
struct CallStackFrame {
EvalInfo &Info;
/// ParmBindings - Parameter bindings for this function call, indexed by
/// parameters' function scope indices.
- const CCValue *Arguments;
+ const APValue *Arguments;
- typedef llvm::DenseMap<const Expr*, CCValue> MapTy;
+ typedef llvm::DenseMap<const Expr*, APValue> MapTy;
typedef MapTy::const_iterator temp_iterator;
/// Temporaries - Temporary lvalues materialized within this stack frame.
MapTy Temporaries;
CallStackFrame(EvalInfo &Info, SourceLocation CallLoc,
const FunctionDecl *Callee, const LValue *This,
- const CCValue *Arguments);
+ const APValue *Arguments);
~CallStackFrame();
};
/// NextCallIndex - The next call index to assign.
unsigned NextCallIndex;
- typedef llvm::DenseMap<const OpaqueValueExpr*, CCValue> MapTy;
+ typedef llvm::DenseMap<const OpaqueValueExpr*, APValue> MapTy;
/// OpaqueValues - Values used as the common expression in a
/// BinaryConditionalOperator.
MapTy OpaqueValues;
EvaluatingDecl(0), EvaluatingDeclValue(0), HasActiveDiagnostic(false),
CheckingPotentialConstantExpression(false), IntExprEvaluatorDepth(0) {}
- const CCValue *getOpaqueValue(const OpaqueValueExpr *e) const {
+ const APValue *getOpaqueValue(const OpaqueValueExpr *e) const {
MapTy::const_iterator i = OpaqueValues.find(e);
if (i == OpaqueValues.end()) return 0;
return &i->second;
CallStackFrame::CallStackFrame(EvalInfo &Info, SourceLocation CallLoc,
const FunctionDecl *Callee, const LValue *This,
- const CCValue *Arguments)
+ const APValue *Arguments)
: Info(Info), Caller(Info.CurrentCall), CallLoc(CallLoc), Callee(Callee),
Index(Info.NextCallIndex++), This(This), Arguments(Arguments) {
Info.CurrentCall = this;
Out << ", ";
const ParmVarDecl *Param = *I;
- const CCValue &Arg = Frame->Arguments[ArgIndex];
- if (!Arg.isLValue() || Arg.getLValueDesignator().Invalid)
- Arg.printPretty(Out, Frame->Info.Ctx, Param->getType());
- else {
- // Convert the CCValue to an APValue without checking for constantness.
- APValue Value(Arg.getLValueBase(), Arg.getLValueOffset(),
- Arg.getLValueDesignator().Entries,
- Arg.getLValueDesignator().IsOnePastTheEnd,
- Arg.getLValueCallIndex());
- Value.printPretty(Out, Frame->Info.Ctx, Param->getType());
- }
+ const APValue &Arg = Frame->Arguments[ArgIndex];
+ Arg.printPretty(Out, Frame->Info.Ctx, Param->getType());
if (ArgIndex == 0 && IsMemberCall)
Out << "->" << *Frame->Callee << '(';
APSInt &getComplexIntReal() { return IntReal; }
APSInt &getComplexIntImag() { return IntImag; }
- void moveInto(CCValue &v) const {
+ void moveInto(APValue &v) const {
if (isComplexFloat())
- v = CCValue(FloatReal, FloatImag);
+ v = APValue(FloatReal, FloatImag);
else
- v = CCValue(IntReal, IntImag);
+ v = APValue(IntReal, IntImag);
}
- void setFrom(const CCValue &v) {
+ void setFrom(const APValue &v) {
assert(v.isComplexFloat() || v.isComplexInt());
if (v.isComplexFloat()) {
makeComplexFloat();
SubobjectDesignator &getLValueDesignator() { return Designator; }
const SubobjectDesignator &getLValueDesignator() const { return Designator;}
- void moveInto(CCValue &V) const {
- V = CCValue(Base, Offset, CallIndex, Designator);
+ void moveInto(APValue &V) const {
+ if (Designator.Invalid)
+ V = APValue(Base, Offset, APValue::NoLValuePath(), CallIndex);
+ else
+ V = APValue(Base, Offset, Designator.Entries,
+ Designator.IsOnePastTheEnd, CallIndex);
}
- void setFrom(const CCValue &V) {
+ void setFrom(ASTContext &Ctx, const APValue &V) {
assert(V.isLValue());
Base = V.getLValueBase();
Offset = V.getLValueOffset();
CallIndex = V.getLValueCallIndex();
- Designator = V.getLValueDesignator();
+ Designator = SubobjectDesignator(Ctx, V);
}
void set(APValue::LValueBase B, unsigned I = 0) {
DeclAndIsDerivedMember.getPointer()->getDeclContext());
}
- void moveInto(CCValue &V) const {
- V = CCValue(getDecl(), isDerivedMember(), Path);
+ void moveInto(APValue &V) const {
+ V = APValue(getDecl(), isDerivedMember(), Path);
}
- void setFrom(const CCValue &V) {
+ void setFrom(const APValue &V) {
assert(V.isMemberPointer());
DeclAndIsDerivedMember.setPointer(V.getMemberPointerDecl());
DeclAndIsDerivedMember.setInt(V.isMemberPointerToDerivedMember());
};
}
-static bool Evaluate(CCValue &Result, EvalInfo &Info, const Expr *E);
+static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E);
static bool EvaluateInPlace(APValue &Result, EvalInfo &Info,
const LValue &This, const Expr *E,
CheckConstantExpressionKind CCEK = CCEK_Constant,
EvalInfo &Info);
static bool EvaluateTemporary(const Expr *E, LValue &Result, EvalInfo &Info);
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
-static bool EvaluateIntegerOrLValue(const Expr *E, CCValue &Result,
+static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result,
EvalInfo &Info);
static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info);
static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info);
}
/// Check that this reference or pointer core constant expression is a valid
-/// value for an address or reference constant expression. Type T should be
-/// either LValue or CCValue. Return true if we can fold this expression,
-/// whether or not it's a constant expression.
+/// value for an address or reference constant expression. Return true if we
+/// can fold this expression, whether or not it's a constant expression.
static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc,
QualType Type, const LValue &LVal) {
bool IsReferenceType = Type->isReferenceType();
}
if (Value.isLValue()) {
- CCValue Val(Info.Ctx, Value, CCValue::GlobalValue());
LValue LVal;
- LVal.setFrom(Val);
+ LVal.setFrom(Info.Ctx, Value);
return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal);
}
return Decl && Decl->isWeak();
}
-static bool EvalPointerValueAsBool(const CCValue &Value, bool &Result) {
+static bool EvalPointerValueAsBool(const APValue &Value, bool &Result) {
// A null base expression indicates a null pointer. These are always
// evaluatable, and they are false unless the offset is zero.
if (!Value.getLValueBase()) {
return !Decl || !Decl->isWeak();
}
-static bool HandleConversionToBool(const CCValue &Val, bool &Result) {
+static bool HandleConversionToBool(const APValue &Val, bool &Result) {
switch (Val.getKind()) {
case APValue::Uninitialized:
return false;
static bool EvaluateAsBooleanCondition(const Expr *E, bool &Result,
EvalInfo &Info) {
assert(E->isRValue() && "missing lvalue-to-rvalue conv in bool condition");
- CCValue Val;
+ APValue Val;
if (!Evaluate(Val, Info, E))
return false;
return HandleConversionToBool(Val, Result);
static bool EvalAndBitcastToAPInt(EvalInfo &Info, const Expr *E,
llvm::APInt &Res) {
- CCValue SVal;
+ APValue SVal;
if (!Evaluate(SVal, Info, E))
return false;
if (SVal.isInt()) {
/// Try to evaluate the initializer for a variable declaration.
static bool EvaluateVarDeclInit(EvalInfo &Info, const Expr *E,
const VarDecl *VD,
- CallStackFrame *Frame, CCValue &Result) {
+ CallStackFrame *Frame, APValue &Result) {
// If this is a parameter to an active constexpr function call, perform
// argument substitution.
if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD)) {
// If we're currently evaluating the initializer of this declaration, use that
// in-flight value.
if (Info.EvaluatingDecl == VD) {
- Result = CCValue(Info.Ctx, *Info.EvaluatingDeclValue,
- CCValue::GlobalValue());
+ Result = *Info.EvaluatingDeclValue;
return !Result.isUninit();
}
Info.addNotes(Notes);
}
- Result = CCValue(Info.Ctx, *VD->getEvaluatedValue(), CCValue::GlobalValue());
+ Result = *VD->getEvaluatedValue();
return true;
}
/// Extract the designated sub-object of an rvalue.
static bool ExtractSubobject(EvalInfo &Info, const Expr *E,
- CCValue &Obj, QualType ObjType,
+ APValue &Obj, QualType ObjType,
const SubobjectDesignator &Sub, QualType SubType) {
if (Sub.Invalid)
// A diagnostic will have already been produced.
if (O->isLValue()) {
assert(I == N - 1 && "extracting subobject of character?");
assert(!O->hasLValuePath() || O->getLValuePath().empty());
- Obj = CCValue(ExtractStringLiteralCharacter(
+ Obj = APValue(ExtractStringLiteralCharacter(
Info, O->getLValueBase().get<const Expr*>(), Index));
return true;
} else if (O->getArrayInitializedElts() > Index)
}
assert(I == N - 1 && "extracting subobject of scalar?");
if (O->isComplexInt()) {
- Obj = CCValue(Index ? O->getComplexIntImag()
+ Obj = APValue(Index ? O->getComplexIntImag()
: O->getComplexIntReal());
} else {
assert(O->isComplexFloat());
- Obj = CCValue(Index ? O->getComplexFloatImag()
+ Obj = APValue(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal());
}
return true;
}
}
- Obj = CCValue(Info.Ctx, *O, CCValue::GlobalValue());
+ Obj = APValue(*O);
return true;
}
/// \param RVal - The produced value will be placed here.
static bool HandleLValueToRValueConversion(EvalInfo &Info, const Expr *Conv,
QualType Type,
- const LValue &LVal, CCValue &RVal) {
+ const LValue &LVal, APValue &RVal) {
// In C, an lvalue-to-rvalue conversion is never a constant expression.
if (!Info.getLangOpts().CPlusPlus)
Info.CCEDiag(Conv->getExprLoc(), diag::note_invalid_subexpr_in_const_expr);
// We represent a string literal array as an lvalue pointing at the
// corresponding expression, rather than building an array of chars.
// FIXME: Support PredefinedExpr, ObjCEncodeExpr, MakeStringConstant
- RVal = CCValue(Info.Ctx,
- APValue(Base, CharUnits::Zero(), APValue::NoLValuePath(), 0),
- CCValue::GlobalValue());
+ RVal = APValue(Base, CharUnits::Zero(), APValue::NoLValuePath(), 0);
} else {
Info.Diag(Conv->getExprLoc(), diag::note_invalid_subexpr_in_const_expr);
return false;
}
// Evaluate a statement.
-static EvalStmtResult EvaluateStmt(CCValue &Result, EvalInfo &Info,
+static EvalStmtResult EvaluateStmt(APValue &Result, EvalInfo &Info,
const Stmt *S) {
switch (S->getStmtClass()) {
default:
}
namespace {
-typedef SmallVector<CCValue, 8> ArgVector;
+typedef SmallVector<APValue, 8> ArgVector;
}
/// EvaluateArgs - Evaluate the arguments to a function call.
static bool HandleFunctionCall(SourceLocation CallLoc,
const FunctionDecl *Callee, const LValue *This,
ArrayRef<const Expr*> Args, const Stmt *Body,
- EvalInfo &Info, CCValue &Result) {
+ EvalInfo &Info, APValue &Result) {
ArgVector ArgValues(Args.size());
if (!EvaluateArgs(Args, ArgValues, Info))
return false;
((Definition->isCopyConstructor() && Definition->isTrivial()) ||
(Definition->isMoveConstructor() && Definition->isTrivial()))) {
LValue RHS;
- RHS.setFrom(ArgValues[0]);
- CCValue Value;
- if (!HandleLValueToRValueConversion(Info, Args[0], Args[0]->getType(),
- RHS, Value))
- return false;
- assert((Value.isStruct() || Value.isUnion()) &&
- "trivial copy/move from non-class type?");
- // Any CCValue of class type must already be a constant expression.
- Result = Value;
- return true;
+ RHS.setFrom(Info.Ctx, ArgValues[0]);
+ return HandleLValueToRValueConversion(Info, Args[0], Args[0]->getType(),
+ RHS, Result);
}
// Reserve space for the struct members.
class ExprEvaluatorBase
: public ConstStmtVisitor<Derived, RetTy> {
private:
- RetTy DerivedSuccess(const CCValue &V, const Expr *E) {
+ RetTy DerivedSuccess(const APValue &V, const Expr *E) {
return static_cast<Derived*>(this)->Success(V, E);
}
RetTy DerivedZeroInitialization(const Expr *E) {
LValue Obj;
if (!HandleMemberPointerAccess(Info, E, Obj))
return false;
- CCValue Result;
+ APValue Result;
if (!HandleLValueToRValueConversion(Info, E, E->getType(), Obj, Result))
return false;
return DerivedSuccess(Result, E);
}
RetTy VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
- const CCValue *Value = Info.getOpaqueValue(E);
+ const APValue *Value = Info.getOpaqueValue(E);
if (!Value) {
const Expr *Source = E->getSourceExpr();
if (!Source)
const FunctionDecl *Definition = 0;
Stmt *Body = FD->getBody(Definition);
- CCValue Result;
+ APValue Result;
if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition) ||
!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body,
RetTy VisitMemberExpr(const MemberExpr *E) {
assert(!E->isArrow() && "missing call to bound member function?");
- CCValue Val;
+ APValue Val;
if (!Evaluate(Val, Info, E->getBase()))
return false;
LValue LVal;
if (!EvaluateLValue(E->getSubExpr(), LVal, Info))
return false;
- CCValue RVal;
+ APValue RVal;
// Note, we use the subexpression's type in order to retain cv-qualifiers.
if (!HandleLValueToRValueConversion(Info, E, E->getSubExpr()->getType(),
LVal, RVal))
/// Visit a value which is evaluated, but whose value is ignored.
void VisitIgnoredValue(const Expr *E) {
- CCValue Scratch;
+ APValue Scratch;
if (!Evaluate(Scratch, Info, E))
Info.EvalStatus.HasSideEffects = true;
}
LValueExprEvaluatorBase(EvalInfo &Info, LValue &Result) :
ExprEvaluatorBaseTy(Info), Result(Result) {}
- bool Success(const CCValue &V, const Expr *E) {
- Result.setFrom(V);
+ bool Success(const APValue &V, const Expr *E) {
+ Result.setFrom(this->Info.Ctx, V);
return true;
}
return this->Error(E);
if (MD->getType()->isReferenceType()) {
- CCValue RefValue;
+ APValue RefValue;
if (!HandleLValueToRValueConversion(this->Info, E, MD->getType(), Result,
RefValue))
return false;
return Success(VD);
}
- CCValue V;
+ APValue V;
if (!EvaluateVarDeclInit(Info, E, VD, Info.CurrentCall, V))
return false;
return Success(V, E);
PointerExprEvaluator(EvalInfo &info, LValue &Result)
: ExprEvaluatorBaseTy(info), Result(Result) {}
- bool Success(const CCValue &V, const Expr *E) {
- Result.setFrom(V);
+ bool Success(const APValue &V, const Expr *E) {
+ Result.setFrom(Info.Ctx, V);
return true;
}
bool ZeroInitialization(const Expr *E) {
case CK_IntegralToPointer: {
CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
- CCValue Value;
+ APValue Value;
if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
break;
return true;
} else {
// Cast is of an lvalue, no need to change value.
- Result.setFrom(Value);
+ Result.setFrom(Info.Ctx, Value);
return true;
}
}
MemberPointerExprEvaluator(EvalInfo &Info, MemberPtr &Result)
: ExprEvaluatorBaseTy(Info), Result(Result) {}
- bool Success(const CCValue &V, const Expr *E) {
+ bool Success(const APValue &V, const Expr *E) {
Result.setFrom(V);
return true;
}
RecordExprEvaluator(EvalInfo &info, const LValue &This, APValue &Result)
: ExprEvaluatorBaseTy(info), This(This), Result(Result) {}
- bool Success(const CCValue &V, const Expr *E) {
+ bool Success(const APValue &V, const Expr *E) {
Result = V;
return true;
}
case CK_DerivedToBase:
case CK_UncheckedDerivedToBase: {
- CCValue DerivedObject;
+ APValue DerivedObject;
if (!Evaluate(DerivedObject, Info, E->getSubExpr()))
return false;
if (!DerivedObject.isStruct())
Result = APValue(V.data(), V.size());
return true;
}
- bool Success(const CCValue &V, const Expr *E) {
+ bool Success(const APValue &V, const Expr *E) {
assert(V.isVector());
Result = V;
return true;
LValue LV;
if (!EvaluateLValue(E->getInit(0), LV, Info))
return false;
- CCValue Val;
+ APValue Val;
LV.moveInto(Val);
return Success(Val, E);
}
namespace {
class IntExprEvaluator
: public ExprEvaluatorBase<IntExprEvaluator, bool> {
- CCValue &Result;
+ APValue &Result;
public:
- IntExprEvaluator(EvalInfo &info, CCValue &result)
+ IntExprEvaluator(EvalInfo &info, APValue &result)
: ExprEvaluatorBaseTy(info), Result(result) {}
bool Success(const llvm::APSInt &SI, const Expr *E) {
"Invalid evaluation result.");
assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
"Invalid evaluation result.");
- Result = CCValue(SI);
+ Result = APValue(SI);
return true;
}
"Invalid evaluation result.");
assert(I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
"Invalid evaluation result.");
- Result = CCValue(APSInt(I));
+ Result = APValue(APSInt(I));
Result.getInt().setIsUnsigned(
E->getType()->isUnsignedIntegerOrEnumerationType());
return true;
bool Success(uint64_t Value, const Expr *E) {
assert(E->getType()->isIntegralOrEnumerationType() &&
"Invalid evaluation result.");
- Result = CCValue(Info.Ctx.MakeIntValue(Value, E->getType()));
+ Result = APValue(Info.Ctx.MakeIntValue(Value, E->getType()));
return true;
}
return Success(Size.getQuantity(), E);
}
- bool Success(const CCValue &V, const Expr *E) {
+ bool Success(const APValue &V, const Expr *E) {
if (V.isLValue() || V.isAddrLabelDiff()) {
Result = V;
return true;
/// an integer rvalue to produce a pointer (represented as an lvalue) instead.
/// Some simple arithmetic on such values is supported (they are treated much
/// like char*).
-static bool EvaluateIntegerOrLValue(const Expr *E, CCValue &Result,
+static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result,
EvalInfo &Info) {
assert(E->isRValue() && E->getType()->isIntegralOrEnumerationType());
return IntExprEvaluator(Info, Result).Visit(E);
}
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info) {
- CCValue Val;
+ APValue Val;
if (!EvaluateIntegerOrLValue(E, Val, Info))
return false;
if (!Val.isInt()) {
if (LHSAddrExpr->getLabel()->getDeclContext() !=
RHSAddrExpr->getLabel()->getDeclContext())
return false;
- Result = CCValue(LHSAddrExpr, RHSAddrExpr);
+ Result = APValue(LHSAddrExpr, RHSAddrExpr);
return true;
}
// Inequalities and subtractions between unrelated pointers have
}
// The LHS of a constant expr is always evaluated and needed.
- CCValue LHSVal;
+ APValue LHSVal;
bool LHSOK = EvaluateIntegerOrLValue(E->getLHS(), LHSVal, Info);
if (!LHSOK && !Info.keepEvaluatingAfterFailure())
if (!Visit(E->getRHS()) || !LHSOK)
return false;
- CCValue &RHSVal = Result;
+ APValue &RHSVal = Result;
// Handle cases like (unsigned long)&a + 4.
if (E->isAdditiveOp() && LHSVal.isLValue() && RHSVal.isInt()) {
if (LHSAddrExpr->getLabel()->getDeclContext() !=
RHSAddrExpr->getLabel()->getDeclContext())
return false;
- Result = CCValue(LHSAddrExpr, RHSAddrExpr);
+ Result = APValue(LHSAddrExpr, RHSAddrExpr);
return true;
}
FloatExprEvaluator(EvalInfo &info, APFloat &result)
: ExprEvaluatorBaseTy(info), Result(result) {}
- bool Success(const CCValue &V, const Expr *e) {
+ bool Success(const APValue &V, const Expr *e) {
Result = V.getFloat();
return true;
}
ComplexExprEvaluator(EvalInfo &info, ComplexValue &Result)
: ExprEvaluatorBaseTy(info), Result(Result) {}
- bool Success(const CCValue &V, const Expr *e) {
+ bool Success(const APValue &V, const Expr *e) {
Result.setFrom(V);
return true;
}
public:
VoidExprEvaluator(EvalInfo &Info) : ExprEvaluatorBaseTy(Info) {}
- bool Success(const CCValue &V, const Expr *e) { return true; }
+ bool Success(const APValue &V, const Expr *e) { return true; }
bool VisitCastExpr(const CastExpr *E) {
switch (E->getCastKind()) {
// Top level Expr::EvaluateAsRValue method.
//===----------------------------------------------------------------------===//
-static bool Evaluate(CCValue &Result, EvalInfo &Info, const Expr *E) {
+static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E) {
// In C, function designators are not lvalues, but we evaluate them as if they
// are.
if (E->isGLValue() || E->getType()->isFunctionType()) {
llvm::APFloat F(0.0);
if (!EvaluateFloat(E, F, Info))
return false;
- Result = CCValue(F);
+ Result = APValue(F);
} else if (E->getType()->isAnyComplexType()) {
ComplexValue C;
if (!EvaluateComplex(E, C, Info))
}
// For any other type, in-place evaluation is unimportant.
- CCValue CoreConstResult;
- if (!Evaluate(CoreConstResult, Info, E))
- return false;
- Result = CoreConstResult.toAPValue();
- return true;
+ return Evaluate(Result, Info, E);
}
/// EvaluateAsRValue - Try to evaluate this expression, performing an implicit
if (!CheckLiteralType(Info, E))
return false;
- CCValue Value;
- if (!::Evaluate(Value, Info, E))
+ if (!::Evaluate(Result, Info, E))
return false;
if (E->isGLValue()) {
LValue LV;
- LV.setFrom(Value);
- if (!HandleLValueToRValueConversion(Info, E, E->getType(), LV, Value))
+ LV.setFrom(Info.Ctx, Result);
+ if (!HandleLValueToRValueConversion(Info, E, E->getType(), LV, Result))
return false;
}
- // Check this core constant expression is a constant expression, and if so,
- // convert it to one.
- Result = Value.toAPValue();
+ // Check this core constant expression is a constant expression.
return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result);
}
const ASTContext &Ctx) const {
EvalResult Scratch;
return EvaluateAsRValue(Scratch, Ctx) &&
- HandleConversionToBool(CCValue(const_cast<ASTContext&>(Ctx),
- Scratch.Val, CCValue::GlobalValue()),
- Result);
+ HandleConversionToBool(Scratch.Val, Result);
}
bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx,
Ctx.getLValueReferenceType(getType()), LV))
return false;
- CCValue Tmp;
- LV.moveInto(Tmp);
- Result.Val = Tmp.toAPValue();
+ LV.moveInto(Result.Val);
return true;
}
SourceLocation Loc = FD->getLocation();
- if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
- APValue Scratch;
+ APValue Scratch;
+ if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD))
HandleConstructorCall(Loc, This, Args, CD, Info, Scratch);
- } else {
- CCValue Scratch;
+ else
HandleFunctionCall(Loc, FD, (MD && MD->isInstance()) ? &This : 0,
Args, FD->getBody(), Info, Scratch);
- }
return Diags.empty();
}