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] A first step to fix 21541


As a first step to fix PR21541, ICE on valid, this fixes the ICE
on the reduced testcase which happens to look like

typedef struct { char ch; } pstr;
const pstr ao = { 'O' };

void test1(void)
{
   *((char *)&ao.ch) = 1;
}

see the audit trail for an analysis.


Bootstrapped on x86_64-unknown-linux-gnu, tested on i686 and
x86_64.  The following new regressions (missed optimizations)
occour:

FAIL: g++.dg/opt/temp1.C execution test
FAIL: g++.dg/tree-ssa/ssa-sra-1.C scan-tree-dump-times link_error 0
FAIL: g++.dg/tree-ssa/ssa-sra-2.C scan-tree-dump-times link_error 0

FAIL: gcc.dg/tree-ssa/ltrans-5.c
FAIL: gcc.dg/tree-ssa/stdarg-2.c
FAIL: gcc.dg/tree-ssa/stdarg-4.c

the following still fail:

FAIL: gcc.c-torture/execute/20031215-1.c compilation,  -O2
FAIL: gcc.c-torture/execute/20031215-1.c compilation,  -O3
-fomit-frame-pointer
FAIL: gcc.c-torture/execute/20031215-1.c compilation,  -O3 -g
FAIL: gcc.c-torture/execute/20031215-1.c compilation,  -Os

I don't know if the sra failures are related to this patch.

Ok for mainline?

Thanks,
Richard.
2005-05-14  Richard Guenther  <rguenth@gcc.gnu.org>

	* fold-const.c: Include tree-flow.h
	(fold_indirect_ref_1): Use STRIP_USELESS_TYPE_CONVERSION.
	* Makefile.in: Fix dependencies.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Conversion
        may not be useless if pointed to types are compatible, but
        pointers were not.

	* gcc.c-torture/compile/20050514.c: New testcase.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.580
diff -c -3 -p -r1.580 fold-const.c
*** fold-const.c	14 May 2005 15:42:01 -0000	1.580
--- fold-const.c	14 May 2005 19:08:47 -0000
*************** Software Foundation, 59 Temple Place - S
*** 58,63 ****
--- 58,64 ----
  #include "hashtab.h"
  #include "langhooks.h"
  #include "md5.h"
+ #include "tree-flow.h"
  
  /* The following constants represent a bit based encoding of GCC's
     comparison operators.  This encoding simplifies transformations
*************** fold_indirect_ref_1 (tree t)
*** 11406,11412 ****
    tree sub = t;
    tree subtype;
  
!   STRIP_NOPS (sub);
    subtype = TREE_TYPE (sub);
    if (!POINTER_TYPE_P (subtype))
      return NULL_TREE;
--- 11407,11413 ----
    tree sub = t;
    tree subtype;
  
!   STRIP_USELESS_TYPE_CONVERSION (sub);
    subtype = TREE_TYPE (sub);
    if (!POINTER_TYPE_P (subtype))
      return NULL_TREE;
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.94
diff -c -3 -p -r2.94 tree-ssa.c
*** tree-ssa.c	8 May 2005 15:07:22 -0000	2.94
--- tree-ssa.c	14 May 2005 19:08:47 -0000
*************** tree_ssa_useless_type_conversion_1 (tree
*** 881,896 ****
  	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
      return true;
  
-   /* Pointers and references are equivalent once we get to GENERIC,
-      so strip conversions that just switch between them.  */
-   else if (POINTER_TYPE_P (inner_type)
-            && POINTER_TYPE_P (outer_type)
- 	   && TYPE_REF_CAN_ALIAS_ALL (inner_type)
- 	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
-            && lang_hooks.types_compatible_p (TREE_TYPE (inner_type),
- 					     TREE_TYPE (outer_type)))
-     return true;
- 
    /* If both the inner and outer types are integral types, then the
       conversion is not necessary if they have the same mode and
       signedness and precision, and both or neither are boolean.  Some
--- 881,886 ----
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1484
diff -c -3 -p -r1.1484 Makefile.in
*** Makefile.in	11 May 2005 16:25:24 -0000	1.1484
--- Makefile.in	14 May 2005 19:08:47 -0000
*************** tree-pretty-print.o : tree-pretty-print.
*** 1883,1889 ****
     $(TM_H) coretypes.h tree-iterator.h tree-chrec.h langhooks.h
  fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(TREE_H) $(FLAGS_H) real.h toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) \
!    $(GGC_H) $(TM_P_H) langhooks.h $(MD5_H)
  diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) input.h toplev.h intl.h \
     $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h
--- 1883,1889 ----
     $(TM_H) coretypes.h tree-iterator.h tree-chrec.h langhooks.h
  fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(TREE_H) $(FLAGS_H) real.h toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) \
!    $(GGC_H) $(TM_P_H) langhooks.h $(MD5_H) $(TREE_FLOW_H)
  diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) input.h toplev.h intl.h \
     $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h



/* The following used to ICE because gimplification removed the
   cast to (char *) and tree checking was not happy about it.  */

typedef struct { char ch; } pstr;
const pstr ao = { 'O' };

void test1(void)
{
   *((char *)&ao.ch) = 1;
}


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