From: Chris Lattner Date: Tue, 27 Nov 2007 21:35:27 +0000 (+0000) Subject: add several cases that Expr::hasStaticStorage missed, pointed out by Oliver Hunt X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cc627111453b75519d5130b57e06256da7b00e8;p=clang add several cases that Expr::hasStaticStorage missed, pointed out by Oliver Hunt git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44376 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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(this)->getSubExpr()->hasStaticStorage(); + case ImplicitCastExprClass: + return cast(this)->getSubExpr()->hasStaticStorage(); case DeclRefExprClass: { const Decl *D = cast(this)->getDecl(); if (const VarDecl *VD = dyn_cast(D)) @@ -373,6 +380,8 @@ bool Expr::hasStaticStorage() const { case MemberExprClass: const MemberExpr *M = cast(this); return !M->isArrow() && M->getBase()->hasStaticStorage(); + case ArraySubscriptExprClass: + return cast(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]); +