diff options
-rw-r--r-- | AST/Expr.cpp | 9 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 3 | ||||
-rw-r--r-- | test/Sema/init.c | 4 |
3 files changed, 15 insertions, 1 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 9bc6b903ad..33b56e52b6 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -360,10 +360,17 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { return MLV_Valid; } +/// hasStaticStorage - Return true if this expression has static storage +/// duration. This means that the address of this expression is a link-time +/// constant. bool Expr::hasStaticStorage() const { switch (getStmtClass()) { default: return false; + case ParenExprClass: + return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage(); + case ImplicitCastExprClass: + return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage(); case DeclRefExprClass: { const Decl *D = cast<DeclRefExpr>(this)->getDecl(); if (const VarDecl *VD = dyn_cast<VarDecl>(D)) @@ -373,6 +380,8 @@ bool Expr::hasStaticStorage() const { case MemberExprClass: const MemberExpr *M = cast<MemberExpr>(this); return !M->isArrow() && M->getBase()->hasStaticStorage(); + case ArraySubscriptExprClass: + return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage(); } } diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 6ba60f2209..7ee3afc6b7 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -106,7 +106,8 @@ public: bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const; /// hasStaticStorage - Return true if this expression has static storage - /// duration. + /// duration. This means that the address of this expression is a link-time + /// constant. bool hasStaticStorage() const; static bool classof(const Stmt *T) { diff --git a/test/Sema/init.c b/test/Sema/init.c index 71b1d63d61..2f6df64d09 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -4,3 +4,7 @@ typedef void (* fp)(void); void foo(void); fp a[1] = { foo }; +int myArray[5] = {1, 2, 3, 4, 5}; +int *myPointer2 = myArray; +int *myPointer = &(myArray[2]); + |