diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 1a8b46df60..1c32d7cd77 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -436,31 +436,31 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const { return MLV_Valid; } -/// hasStaticStorage - Return true if this expression has static storage +/// hasGlobalStorage - 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 { +bool Expr::hasGlobalStorage() const { switch (getStmtClass()) { default: return false; case ParenExprClass: - return cast(this)->getSubExpr()->hasStaticStorage(); + return cast(this)->getSubExpr()->hasGlobalStorage(); case ImplicitCastExprClass: - return cast(this)->getSubExpr()->hasStaticStorage(); + return cast(this)->getSubExpr()->hasGlobalStorage(); case CompoundLiteralExprClass: return cast(this)->isFileScope(); case DeclRefExprClass: { const Decl *D = cast(this)->getDecl(); if (const VarDecl *VD = dyn_cast(D)) - return VD->hasStaticStorage(); + return VD->hasGlobalStorage(); return false; } case MemberExprClass: { const MemberExpr *M = cast(this); - return !M->isArrow() && M->getBase()->hasStaticStorage(); + return !M->isArrow() && M->getBase()->hasGlobalStorage(); } case ArraySubscriptExprClass: - return cast(this)->getBase()->hasStaticStorage(); + return cast(this)->getBase()->hasGlobalStorage(); case PreDefinedExprClass: return true; } @@ -539,7 +539,7 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { // C99 6.6p9 if (Exp->getOpcode() == UnaryOperator::AddrOf) { - if (!Exp->getSubExpr()->hasStaticStorage()) { + if (!Exp->getSubExpr()->hasGlobalStorage()) { if (Loc) *Loc = getLocStart(); return false; } diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 7f7e3afa39..06c0d73d08 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -292,38 +292,24 @@ protected: class VarDecl : public ValueDecl { public: enum StorageClass { - None, Extern, Static, Auto, Register, PrivateExtern + None, Auto, Register, Extern, Static, PrivateExtern }; StorageClass getStorageClass() const { return (StorageClass)SClass; } const Expr *getInit() const { return Init; } Expr *getInit() { return Init; } void setInit(Expr *I) { Init = I; } - - /// hasAutoStorage - Returns true if either the implicit or explicit - /// storage class of a variable is "auto." In particular, variables - /// declared within a function that lack a storage keyword are - /// implicitly "auto", but are represented internally with a storage - /// class of None. - bool hasAutoStorage() const { - return getStorageClass() == Auto || - (getStorageClass() == None && getKind() != FileVar); - } - - /// hasStaticStorage - Returns true if either the implicit or - /// explicit storage class of a variable is "static." In - /// particular, variables declared within a file (outside of a - /// function) that lack a storage keyword are implicitly "static," - /// but are represented internally with a storage class of "None". - bool hasStaticStorage() const { - if (getStorageClass() == Static) return true; - return getKind() == FileVar; - } /// hasLocalStorage - Returns true if a variable with function scope /// is a non-static local variable. bool hasLocalStorage() const { - return hasAutoStorage() || getStorageClass() == Register; + if (getStorageClass() == None) + return getKind() != FileVar; + + // Return true for: Auto, Register. + // Return false for: Extern, Static, PrivateExtern. + + return getStorageClass() <= Register; } /// hasGlobalStorage - Returns true for all variables that do not diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 453f754f8f..11acbe54b0 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -106,10 +106,10 @@ public: /// isConstantExpr - Return true if this expression is a valid constant expr. bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const; - /// hasStaticStorage - Return true if this expression has static storage + /// hasGlobalStorage - Return true if this expression has static storage /// duration. This means that the address of this expression is a link-time /// constant. - bool hasStaticStorage() const; + bool hasGlobalStorage() const; /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return /// its subexpression. If that subexpression is also a ParenExpr,