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]

PR c/10308



/**
 * compile with:
 *   gcc -O2 -c gcc-bug.c
 * or
 *   gcc -O -fgcse -c gcc-bug.c
 *
 * add -DOTHER_CASE to test with the other code chunk.
 */

struct list {
      int *entries;
      int num_entries;
};

struct container {
      /* if I remove the following dummy, gcc doesn't crash */
      char dummy;
      struct list lst;
};

static inline int set_idx(struct list * const this, int idx) {
   /* two different code chunks that both are sufficient to crash
    * gcc.  */
#ifndef OTHER_CASE

   /* without the "if", gcc doesn't crash */
   if(this)
      return this->entries[idx] = 42;
   /* it doesn't matter whether I have a return here or not */

#else

   return this->num_entries ? this->entries[idx] : 0;

#endif
}

void somefunc(int idx) {
   /* If I use a NULL pointer instead, gcc doesn't crash*/
   struct container *cont = dummy();
   int i;
   for(i = 0; i < cont->lst.num_entries; ++i) {
      /* The following line has a bug. The "&i" parameter should be
       * "i" instead (since the set_idx takes an "int" as second
       * parameter). If I correct it, gcc doesn't crash */
      int foo = set_idx(&cont->lst, &i);

      /* if I don't use "foo" twice here, gcc doesn't crash */
      dummy2(foo);
      dummy2(foo);
   }
}
Tue Apr  8 20:38:23 CEST 2003  Jan Hubicka  <jh at suse dot cz>
	PR c/10308
	* reload.c (find_reloads_address_1): Reload plus at the place of
	index register.
Index: reload.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reload.c,v
retrieving revision 1.211
diff -c -3 -p -r1.211 reload.c
*** reload.c	26 Mar 2003 07:48:13 -0000	1.211
--- reload.c	8 Apr 2003 18:36:09 -0000
*************** find_reloads_address_1 (mode, x, context
*** 5272,5277 ****
--- 5272,5290 ----
  						       SUBREG_BYTE (orig_op1),
  						       GET_MODE (orig_op1))));
  	  }
+ 	/* Plus in the index register may be created only as a result of
+ 	   register remateralization for expresion like &localvar*4.  Reload it.
+ 	   It may be possible to combine the displacement on the outer level,
+ 	   but it is probably not worthwhile to do so.  */
+ 	if (context)
+ 	  {
+ 	    find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
+ 				  opnum, ADDR_TYPE (type), ind_levels, insn);
+ 	    push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
+ 			 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
+ 			 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
+ 	    return 1;
+ 	  }
  
  	if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
  	    || code0 == ZERO_EXTEND || code1 == MEM)


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