From e8761c8fe2ee6b628104a0885f49fd3c21c08a4f Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 20 Feb 2009 01:57:15 +0000 Subject: [PATCH] Add support for * (unary dereference) operator to ExprConstant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65105 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 9 +++++++++ test/Sema/const-eval.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index fe44297438..0fcbdf12f0 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -157,6 +157,7 @@ public: APValue VisitMemberExpr(MemberExpr *E); APValue VisitStringLiteral(StringLiteral *E) { return APValue(E, 0); } APValue VisitArraySubscriptExpr(ArraySubscriptExpr *E); + APValue VisitUnaryDeref(UnaryOperator *E); }; } // end anonymous namespace @@ -234,6 +235,14 @@ APValue LValueExprEvaluator::VisitArraySubscriptExpr(ArraySubscriptExpr *E) return Result; } +APValue LValueExprEvaluator::VisitUnaryDeref(UnaryOperator *E) +{ + APValue Result; + if (!EvaluatePointer(E->getSubExpr(), Result, Info)) + return APValue(); + return Result; +} + //===----------------------------------------------------------------------===// // Pointer Evaluation //===----------------------------------------------------------------------===// diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index af785e4bdd..30075d5c77 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -38,3 +38,5 @@ EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1); struct s { int a[(int)-1.0f]; // expected-error {{array size is negative}} }; + +EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));