This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFC: folding of literal array refs
- From: Dirk Mueller <dmueller at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 27 Apr 2006 16:04:33 +0200
- Subject: RFC: folding of literal array refs
Hi,
recently I noticed that code like
if ("foo"[0] == 'g')
return 1;
return 0;
is properly const folded, while
if (((const char*)"foo")[0] == 'g')
return 1;
return 0;
is not. This is because the types don't match. the first variant has a
"readonly" in the type node, the 2nd one doesn't.
the patch below fixes this, but I'm unsure if its the most correct approach
(no regtest failures):
--- fold-const.c (revision 113296)
+++ fold-const.c (working copy)
@@ -12220,7 +12220,8 @@
}
if (string
- && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (string))
+ && lang_hooks.types_compatible_p (TREE_TYPE (exp),
+ TREE_TYPE (TREE_TYPE (string)))
&& TREE_CODE (string) == STRING_CST
&& TREE_CODE (index) == INTEGER_CST
&& compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
Comments?
Thanks,
Dirk