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]

C++ PATCH: Fix PR 6196


This patch fixes PR c++/6196, a problem with the address-of-label
extension.  The PR points out that we were forgetting to do the
lvalue-to-rvalue conversion; I also figured out that we were
mishandling the extension in templates.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-08-29  Mark Mitchell  <mark@codesourcery.com>

	PR c++/6196
	* pt.c (tsubst_copy_and_build): Correct handling of
	address-of-label extension.
	* semantics.c (finish_goto_stmt): The address of a label must go
	through the lvalue-to-rvalue conversion.

2003-08-29  Mark Mitchell  <mark@codesourcery.com>

	PR c++/6196
	* g++.dg/ext/label1.C: New test.
	* g++.dg/ext/label2.C: Likewise.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.765
diff -c -5 -p -r1.765 pt.c
*** cp/pt.c	25 Aug 2003 15:47:42 -0000	1.765
--- cp/pt.c	29 Aug 2003 23:06:21 -0000
*************** tsubst_copy_and_build (tree t, 
*** 7970,7979 ****
--- 7970,7981 ----
  	op1 = tsubst_qualified_id (op1, args, complain, in_decl, 
  				   /*done=*/true, /*address_p=*/true);
        else
  	op1 = tsubst_non_call_postfix_expression (op1, args, complain, 
  						  in_decl);
+       if (TREE_CODE (op1) == LABEL_DECL)
+ 	return finish_label_address_expr (DECL_NAME (op1));
        return build_x_unary_op (ADDR_EXPR, op1);
  
      case PLUS_EXPR:
      case MINUS_EXPR:
      case MULT_EXPR:
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.350
diff -c -5 -p -r1.350 semantics.c
*** cp/semantics.c	21 Aug 2003 03:20:54 -0000	1.350
--- cp/semantics.c	29 Aug 2003 23:06:22 -0000
*************** finish_goto_stmt (tree destination)
*** 376,392 ****
  
    /* We warn about unused labels with -Wunused.  That means we have to
       mark the used labels as used.  */
    if (TREE_CODE (destination) == LABEL_DECL)
      TREE_USED (destination) = 1;
!     
!   if (TREE_CODE (destination) != LABEL_DECL)
!     /* We don't inline calls to functions with computed gotos.
!        Those functions are typically up to some funny business,
!        and may be depending on the labels being at particular
!        addresses, or some such.  */
!     DECL_UNINLINABLE (current_function_decl) = 1;
    
    check_goto (destination);
  
    return add_stmt (build_stmt (GOTO_STMT, destination));
  }
--- 376,396 ----
  
    /* We warn about unused labels with -Wunused.  That means we have to
       mark the used labels as used.  */
    if (TREE_CODE (destination) == LABEL_DECL)
      TREE_USED (destination) = 1;
!   else
!     {
!       /* The DESTINATION is being used as an rvalue.  */
!       if (!processing_template_decl)
! 	destination = decay_conversion (destination);
!       /* We don't inline calls to functions with computed gotos.
! 	 Those functions are typically up to some funny business,
! 	 and may be depending on the labels being at particular
! 	 addresses, or some such.  */
!       DECL_UNINLINABLE (current_function_decl) = 1;
!     }
    
    check_goto (destination);
  
    return add_stmt (build_stmt (GOTO_STMT, destination));
  }
Index: testsuite/g++.dg/ext/label1.C
===================================================================
RCS file: testsuite/g++.dg/ext/label1.C
diff -N testsuite/g++.dg/ext/label1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/label1.C	29 Aug 2003 23:06:23 -0000
***************
*** 0 ****
--- 1,8 ----
+ // { dg-options "" }
+ 
+ int main(void) {
+   static const void* lbls[2][2] = {{&&lbl0, &&lbl0}, {&&lbl0, &&lbl0}};
+   goto *lbls[0];
+  lbl0:
+   ;
+ }
Index: testsuite/g++.dg/ext/label2.C
===================================================================
RCS file: testsuite/g++.dg/ext/label2.C
diff -N testsuite/g++.dg/ext/label2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/label2.C	29 Aug 2003 23:06:23 -0000
***************
*** 0 ****
--- 1,11 ----
+ // { dg-options "" }
+ 
+ template <typename T>
+ void f() {
+  l:
+   void *p[] = { &&l };
+ 
+   goto *p;
+ }
+ 
+ template void f<int>();


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