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]

[RFA:] expr.c and test-case, obvious: don't honor flag_force_addr outside function context.


This change
<URL:http://gcc.gnu.org/ml/gcc-patches/2001-11/msg00084.html>;
that is:
*************** expand_expr (exp, target, tmode, modifie
*** 8671,8676 ****
--- 8671,8684 ----
  	 return a zero.  */
        else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
  	return const0_rtx;
+       /* If we are taking the address of a constant and are at the
+ 	 top level, we have to use output_constant_def since we can't
+ 	 call force_const_mem at top level.  */
+       else if (cfun == 0
+ 	       && (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
+ 		   || (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0)))
+ 		       == 'c')))
+ 	op0 = XEXP (output_constant_def (TREE_OPERAND (exp, 0), 0), 0);
        else
  	{
  	  /* We make sure to pass const0_rtx down if we came in with

caused top-level-emitted address constants outside functions, as
found in pointer initializers, to drop past the else-block above
(that used to somehow handle them though apparently had a bug),
and into this code, where the brace matches the one above:

...
	}

      if (flag_force_addr && GET_CODE (op0) != REG)
	op0 = force_reg (Pmode, op0);

So things break with a NULL-pointer SEGV and ICE for such
initializers and -fforce-addr or if flag_force_addr is set in
OPTIMIZATION_OPTIONS, because you can't emit code to set
registers at the top-level.  With that said, I think it's safe
to say that the fix is obvious; to add "&& cfun != 0" to the
test above.  I haven't checked it in as an obvious fix though,
since it's beyond the typo category.

This patch, together with the patch at
<URL:http://gcc.gnu.org/ml/gcc-patches/2001-11/msg01407.html>
fixes the test-case, derived from cplus-dem.c and lets cris-elf
build again.  It sets flag_force_addr in OPTIMIZATION_OPTIONS
because at one time it was measured as being beneficial.
AFAICS, there were previously no test-cases using -fforce-addr.

Bootstrapped and checked with no regressions on
i686-pc-linux-gnu, built and checked on
mmix-knuth-mmixware+mmixware-sim, h8300-hitachi-hms+h8300-sim,
i960-unknown-coff+i960-sim, m32r-unknown-elf+m32r-sim,
mn10300-unknown-elf+mn10300-sim,
powerpc-unknown-eabisim+powerpc-sim.  Not that they set
flag_force_addr or something, but still since it was easy: it
took (with an existing setup) no brain cycles and just hours,
while review usually takes weeks and yet days for other people
if something breaks.

Ok to commit, with testcase?

gcc:
	* expr.c (expand_expr, case ADDR_EXPR): Don't honor
	flag_force_addr outside function context.

gcc/testsuite:
	* gcc.dg/20011124-1.c: New test.

*** /dev/null	Tue Jan  1 05:00:00 1980
--- gcc.dg/20011124-1.c	Sat Nov 24 16:13:37 2001
***************
*** 0 ****
--- 1,16 ----
+ /* Copyright (C) 2001  Free Software Foundation.
+    by Hans-Peter Nilsson  <hp@axis.com>  */
+ 
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fforce-addr" } */
+ 
+ const char foo[] = "fum";
+ const struct fi
+ {
+   const char *const in;
+   const char *const out;
+   const int flags;
+ } fie[] = {
+   {"nw", " new", 0},
+   {"dl", foo, 1}
+ };
Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.c,v
retrieving revision 1.384
diff -p -c -r1.384 expr.c
*** expr.c	2001/11/21 23:32:02	1.384
--- expr.c	2001/11/24 13:13:17
*************** expand_expr (exp, target, tmode, modifie
*** 8800,8806 ****
  	  op0 = force_operand (XEXP (op0, 0), target);
  	}
  
!       if (flag_force_addr && GET_CODE (op0) != REG)
  	op0 = force_reg (Pmode, op0);
  
        if (GET_CODE (op0) == REG
--- 8800,8806 ----
  	  op0 = force_operand (XEXP (op0, 0), target);
  	}
  
!       if (flag_force_addr && GET_CODE (op0) != REG && cfun != 0)
  	op0 = force_reg (Pmode, op0);
  
        if (GET_CODE (op0) == REG

brgds, H-P


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