This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded



------- Comment #22 from rguenth at gcc dot gnu dot org  2006-05-08 10:07 -------
Doesn't really work, it misses support for STRING_CST.  See PR22303.

static const char *foo = "?";

char foobar () { return foo[0]; }

Something like the following should fix it (once fold_read_from_constant_string
is fixed):

Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c      (revision 113606)
--- tree-ssa-ccp.c      (working copy)
*************** fold_const_aggregate_ref (tree t)
*** 1011,1020 ****
        }

        if (ctor == NULL_TREE
!         || TREE_CODE (ctor) != CONSTRUCTOR
          || !TREE_STATIC (ctor))
        return NULL_TREE;

        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);
--- 1011,1024 ----
        }

        if (ctor == NULL_TREE
!         || TREE_CODE (ctor) != CONSTRUCTOR
          || !TREE_STATIC (ctor))
        return NULL_TREE;

        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);
--- 1011,1024 ----
        }

        if (ctor == NULL_TREE
!         || (TREE_CODE (ctor) != CONSTRUCTOR
!             && TREE_CODE (ctor) != STRING_CST)
          || !TREE_STATIC (ctor))
        return NULL_TREE;

+       if (TREE_CODE (ctor) == STRING_CST)
+       return fold_read_from_constant_string (t);
+ 
        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |22303
              nThis|                            |
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]