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]

C++ patch: fix asm label extension



One of Mark Mitchell's recent changes prevents the use of asm labels
on local variables.  cc1plus dies with a my_friendly_assert when asked
to compile code like this...

void foo ()
{ register const char *h asm("%esi") = "hey"; }

There are many ways to fix this, and here's one suggestion:

1999-09-04  Anthony Green  <green@cygnus.com>

	* decl.c (initialize_local_var): Add asmspec argument.  Check
	asmspec before asserting on the existance of rtl.
	(cp_finish_decl): Call initialize_local_var with asmspec.
	* cp-tree.h: Change initialize_local_var prototype.
	* semantics.c (expand_stmt): Call initialize_local_var with
	0 asmspec argument.


Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/decl.c,v
retrieving revision 1.425
diff -u -r1.425 decl.c
--- decl.c	1999/09/04 02:19:26	1.425
+++ decl.c	1999/09/04 16:56:59
@@ -7770,10 +7770,11 @@
 /* Generate code to initialized DECL (a local variable).  */
 
 void
-initialize_local_var (decl, init, flags)
+initialize_local_var (decl, init, flags, asmspec)
      tree decl;
      tree init;
      int flags;
+     const char *asmspec;
 {
   tree type;
   tree cleanup;
@@ -7790,9 +7791,11 @@
     }
 
   if (DECL_RTL (decl))
-    /* Only a RESULT_DECL should have non-NULL RTL when arriving here.
-       All other local variables are assigned RTL in this function.  */
-    my_friendly_assert (TREE_CODE (decl) == RESULT_DECL, 19990828);
+    /* The only two cases in which decl should have non-NULL RTL when
+       arriving here are if it is a RESULT_DECL, or if an asm label
+       was used.  All other local variables are assigned RTL in this
+       function.  */
+    my_friendly_assert (asmspec || TREE_CODE (decl) == RESULT_DECL, 19990828);
   else
     /* Create RTL for this variable.  */
     expand_decl (decl);
@@ -8060,7 +8063,7 @@
 	     statement-tree, we'll do the initialization when we
 	     expand the tree.  */
 	  if (!building_stmt_tree ())
-	    initialize_local_var (decl, init, flags);
+	    initialize_local_var (decl, init, flags, asmspec);
 	  else if (init || DECL_INITIAL (decl) == error_mark_node)
 	    DECL_INITIAL (decl) = init;
 	}
Index: gcc/cp/cp-tree.h
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.283
diff -u -r1.283 cp-tree.h
--- cp-tree.h	1999/09/04 02:19:25	1.283
+++ cp-tree.h	1999/09/04 16:57:10
@@ -3044,7 +3044,7 @@
 extern void cp_finish_decl			PROTO((tree, tree, tree, int, int));
 extern void finish_decl				PROTO((tree, tree, tree));
 extern void maybe_inject_for_scope_var          PROTO((tree));
-extern void initialize_local_var                PROTO((tree, tree, int));
+extern void initialize_local_var                PROTO((tree, tree, int, const char *));
 extern void expand_static_init			PROTO((tree, tree));
 extern void start_handler_parms                 PROTO((tree, tree));
 extern int complete_array_type			PROTO((tree, tree, int));
Index: gcc/cp/semantics.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/semantics.c,v
retrieving revision 1.70
diff -u -r1.70 semantics.c
--- semantics.c	1999/09/02 19:14:06	1.70
+++ semantics.c	1999/09/04 16:57:14
@@ -2024,7 +2024,7 @@
 	    if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
 	      {
 		maybe_inject_for_scope_var (decl);
-		initialize_local_var (decl, DECL_INITIAL (decl), 0);
+		initialize_local_var (decl, DECL_INITIAL (decl), 0, 0);
 	      }
 	  }
 	resume_momentary (i);

-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California


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