fix c++/6747

Richard Henderson rth@redhat.com
Thu Jun 20 16:49:00 GMT 2002


The C++ mark_addressable routine, unlike the C routine:

 (1) References TREE_ADDRESSABLE on trees for which it is not defined.
 (2) Missed put_var_into_stack.

Tested on x86 and alpha.


r~


	* typeck.c (mark_addressable): Don't test TREE_ADDRESSABLE early.
	Call put_var_into_stack.

	* g++.dg/opt/asm1.C: New.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.388.2.9
diff -c -p -d -r1.388.2.9 typeck.c
*** cp/typeck.c	25 Apr 2002 00:14:24 -0000	1.388.2.9
--- cp/typeck.c	20 Jun 2002 20:03:23 -0000
*************** mark_addressable (exp)
*** 4806,4814 ****
  {
    register tree x = exp;
  
-   if (TREE_ADDRESSABLE (x) == 1)
-     return 1;
- 
    while (1)
      switch (TREE_CODE (x))
        {
--- 4806,4811 ----
*************** mark_addressable (exp)
*** 4827,4832 ****
--- 4824,4831 ----
  	    TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
  	    return 1;
  	  }
+ 	/* FALLTHRU */
+ 
        case VAR_DECL:
  	/* Caller should not be trying to mark initialized
  	   constant fields addressable.  */
*************** mark_addressable (exp)
*** 4834,4839 ****
--- 4833,4839 ----
  			    || DECL_IN_AGGR_P (x) == 0
  			    || TREE_STATIC (x)
  			    || DECL_EXTERNAL (x), 314);
+ 	/* FALLTHRU */
  
        case CONST_DECL:
        case RESULT_DECL:
*************** mark_addressable (exp)
*** 4842,4847 ****
--- 4842,4848 ----
  	  warning ("address requested for `%D', which is declared `register'",
  		      x);
  	TREE_ADDRESSABLE (x) = 1;
+ 	put_var_into_stack (x);
  	return 1;
  
        case FUNCTION_DECL:
Index: testsuite/g++.dg/opt/asm1.C
===================================================================
RCS file: testsuite/g++.dg/opt/asm1.C
diff -N testsuite/g++.dg/opt/asm1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/asm1.C	20 Jun 2002 20:03:23 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/6747
+ // { dg-do compile }
+ // { dg-options "-O" }
+ 
+ void foo()
+ {
+   union { double d; char c[sizeof(double)]; } tmp;
+   __asm__ ("" : "=m" (tmp.d));	// { dg-bogus "not directly addressable" }
+ }



More information about the Gcc-patches mailing list