]> granicus.if.org Git - clang/commitdiff
add several cases that Expr::hasStaticStorage missed, pointed out by Oliver Hunt
authorChris Lattner <sabre@nondot.org>
Tue, 27 Nov 2007 21:35:27 +0000 (21:35 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 27 Nov 2007 21:35:27 +0000 (21:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44376 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
include/clang/AST/Expr.h
test/Sema/init.c

index 9bc6b903adb39c005b568461d5876739e85df4ae..33b56e52b6eaac2aadec23adfae1adeb41c5bc82 100644 (file)
@@ -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();
   }
 }
 
index 6ba60f22095ccfccd4471c95db1cb0efab2c04f4..7ee3afc6b787aad30a85dbd8cdcead5c5929c9ff 100644 (file)
@@ -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) { 
index 71b1d63d616bc734f606ddc0edde850b19d49a04..2f6df64d091bcec82359a3809b5d65e515eb92c6 100644 (file)
@@ -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]);
+