diff options
| author | Devang Patel <dpatel@apple.com> | 2011-11-10 17:47:39 +0000 | 
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2011-11-10 17:47:39 +0000 | 
| commit | 63104ad417d5aa02d0d06d0cea7cb6adee875639 (patch) | |
| tree | 00e4e4a6979e1c3ccc21f8dd5c2c2ffd6487d69a /clang/lib | |
| parent | 61db5a59f7a8d1d60c1da66b5e9a4c93ee31ed4d (diff) | |
| download | bcm5719-llvm-63104ad417d5aa02d0d06d0cea7cb6adee875639.tar.gz bcm5719-llvm-63104ad417d5aa02d0d06d0cea7cb6adee875639.zip | |
Revert r144273. It causes clang self-host build failure.
llvm-svn: 144296
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 87 | 
1 files changed, 31 insertions, 56 deletions
| diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index ca936f0ff8c..25c7a90caaa 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1029,9 +1029,8 @@ static bool EvaluateArgs(ArrayRef<const Expr*> Args, ArgVector &ArgValues,  }  /// Evaluate a function call. -static bool HandleFunctionCall(const LValue *This, ArrayRef<const Expr*> Args, -                               const Stmt *Body, EvalInfo &Info, -                               CCValue &Result) { +static bool HandleFunctionCall(ArrayRef<const Expr*> Args, const Stmt *Body, +                               EvalInfo &Info, CCValue &Result) {    // FIXME: Implement a proper call limit, along with a command-line flag.    if (Info.NumCalls >= 1000000 || Info.CallStackDepth >= 512)      return false; @@ -1040,15 +1039,16 @@ static bool HandleFunctionCall(const LValue *This, ArrayRef<const Expr*> Args,    if (!EvaluateArgs(Args, ArgValues, Info))      return false; +  // FIXME: Pass in 'this' for member functions. +  const LValue *This = 0;    CallStackFrame Frame(Info, This, ArgValues.data());    return EvaluateStmt(Result, Info, Body) == ESR_Returned;  }  /// Evaluate a constructor call. -static bool HandleConstructorCall(const LValue &This, -                                  ArrayRef<const Expr*> Args, +static bool HandleConstructorCall(ArrayRef<const Expr*> Args,                                    const CXXConstructorDecl *Definition, -                                  EvalInfo &Info, +                                  EvalInfo &Info, const LValue &This,                                    APValue &Result) {    if (Info.NumCalls >= 1000000 || Info.CallStackDepth >= 512)      return false; @@ -1305,64 +1305,39 @@ public:      const Expr *Callee = E->getCallee();      QualType CalleeType = Callee->getType(); -    const FunctionDecl *FD = 0; -    LValue *This = 0, ThisVal; -    llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs()); +    // FIXME: Handle the case where Callee is a (parenthesized) MemberExpr for a +    // non-static member function. +    if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) +      return DerivedError(E); -    // Extract function decl and 'this' pointer from the callee. -    if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) { -      const MemberExpr *ME = dyn_cast<MemberExpr>(Callee->IgnoreParens()); -      // FIXME: Handle a BinaryOperator callee ('.*' or '->*'). -      if (!ME) -        return DerivedError(Callee); -      if (ME->isArrow()) { -        if (!EvaluatePointer(ME->getBase(), ThisVal, Info)) -          return DerivedError(ME); -      } else { -        if (!EvaluateLValue(ME->getBase(), ThisVal, Info)) -          return DerivedError(ME); -      } -      This = &ThisVal; +    if (!CalleeType->isFunctionType() && !CalleeType->isFunctionPointerType()) +      return DerivedError(E); + +    CCValue Call; +    if (!Evaluate(Call, Info, Callee) || !Call.isLValue() || +        !Call.getLValueBase() || !Call.getLValueOffset().isZero()) +      return DerivedError(Callee); + +    const FunctionDecl *FD = 0; +    if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Call.getLValueBase())) +      FD = dyn_cast<FunctionDecl>(DRE->getDecl()); +    else if (const MemberExpr *ME = dyn_cast<MemberExpr>(Call.getLValueBase()))        FD = dyn_cast<FunctionDecl>(ME->getMemberDecl()); -      if (!FD) -        return DerivedError(ME); -    } else if (CalleeType->isFunctionPointerType()) { -      CCValue Call; -      if (!Evaluate(Call, Info, Callee) || !Call.isLValue() || -          !Call.getLValueBase() || !Call.getLValueOffset().isZero()) -        return DerivedError(Callee); - -      const Expr *Base = Call.getLValueBase(); - -      if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base)) -        FD = dyn_cast<FunctionDecl>(DRE->getDecl()); -      else if (const MemberExpr *ME = dyn_cast<MemberExpr>(Base)) -        FD = dyn_cast<FunctionDecl>(ME->getMemberDecl()); -      if (!FD) -        return DerivedError(Callee); - -      // Overloaded operator calls to member functions are represented as normal -      // calls with 'this' as the first argument. -      const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD); -      if (MD && !MD->isStatic()) { -        if (!EvaluateLValue(Args[0], ThisVal, Info)) -          return DerivedError(Args[0]); -        This = &ThisVal; -        Args = Args.slice(1); -      } +    if (!FD) +      return DerivedError(Callee); -      // Don't call function pointers which have been cast to some other type. -      if (!Info.Ctx.hasSameType(CalleeType->getPointeeType(), FD->getType())) -        return DerivedError(E); -    } +    // Don't call function pointers which have been cast to some other type. +    if (!Info.Ctx.hasSameType(CalleeType->getPointeeType(), FD->getType())) +      return DerivedError(E);      const FunctionDecl *Definition;      Stmt *Body = FD->getBody(Definition);      CCValue CCResult;      APValue Result; +    llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs());      if (Body && Definition->isConstexpr() && !Definition->isInvalidDecl() && -        HandleFunctionCall(This, Args, Body, Info, CCResult) && +        HandleFunctionCall(Args, Body, Info, CCResult) &&          CheckConstantExpression(CCResult, Result))        return DerivedSuccess(CCValue(Result, CCValue::GlobalValue()), E); @@ -1915,8 +1890,8 @@ bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) {        return Visit(ME->GetTemporaryExpr());    llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs()); -  return HandleConstructorCall(This, Args, cast<CXXConstructorDecl>(Definition), -                               Info, Result); +  return HandleConstructorCall(Args, cast<CXXConstructorDecl>(Definition), +                               Info, This, Result);  }  static bool EvaluateRecord(const Expr *E, const LValue &This, | 

