This is the mail archive of the gcc-patches@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]

[PATCH] Fix PR27498, folding of constant string reads


This fixes PR27498 by relaxing the check for matching types to matching
modes as suggested by Roger.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.

Richard.

:ADDPATCH middle-end:

2006-05-07  Dirk Mueller  <dmueller@suse.de>
	Richard Guenther  <rguenther@suse.de>

	PR middle-end/27498
	* fold-const.c (fold_read_from_constant_string): Relax check
	for matching types to matching modes.

	* gcc.dg/tree-ssa/pr27498.c: New testcase.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 113628)
--- fold-const.c	(working copy)
*************** fold_read_from_constant_string (tree exp
*** 12220,12226 ****
  	}
  
        if (string
! 	  && 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
--- 12247,12253 ----
  	}
  
        if (string
! 	  && TYPE_MODE (TREE_TYPE (exp)) == TYPE_MODE (TREE_TYPE (TREE_TYPE (string)))
  	  && TREE_CODE (string) == STRING_CST
  	  && TREE_CODE (index) == INTEGER_CST
  	  && compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
Index: testsuite/gcc.dg/tree-ssa/pr27498.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/pr27498.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/pr27498.c	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-optimized" } */
+ 
+ void zconfdump(void)
+ {
+   char *p, *p2;
+   for (p2 = p; p2; )
+     {
+       char __a0, __a1, __a2;
+       __a0 = ((__const char *) ("\"\\"))[0];
+       if (__a0)
+         return;
+     }
+ }
+ 
+ /* { dg-final { scan-tree-dump-not "goto" "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */


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