Allow cgraph nodes to change name

Jan Hubicka hubicka@ucw.cz
Thu Aug 28 17:38:00 GMT 2003


> > In standardese, I think "must appear before the first occurrence of
> > the identifier that does not constitute a declaration of that
> > identifier without an initializer" is tight enough; it even gets
> > 
> > void *weird_variable = &weird_variable;
> > void *weird_variable asm("with_a_special_name");
> > 
> > right.
> 
> That's a well-specified rule, but I would be interested in hearing
> about strategies to implement it.  For example, consider template
> instantiation in C++.

Hi,
I've been playing with this issue for a while and it seems to be that
everything is working fine after your changes to avoid SET_DECL_ASSEMBLER_NAME.
Only where it seems to be wrong is the following thestcase of renaming function
in the process:

void t()
{
  printf("t");
}
void q()
{
t();
}
void t() asm("ahoj");

void q1()
{
t();
}

This confuses unit-at-a-time quite considerably but it didn't work previously
either so it is probably not big deal.  The attached patch makes us to error on
such testcase.  I tried the idea of allowing asmspec only on first declaration
but I don't know how to figure out whether given declaration is the first while
still allowing builtin declarations.  TREE_USED appears to do what I need together with the check whether the variable has been initialized or function defined.
Does this look OK to you?

Thu Aug 28 15:03:39 CEST 2003  Jan Hubicka  <jh@suse.cz>
	* c-decl.c (finish_decl):  Allow renaming only in the case declaration wasn't used previously.

*** ../gcc.old/c-decl.c	Wed Aug 27 15:32:09 2003
--- c-decl.c	Thu Aug 28 16:04:01 2003
*************** finish_decl (tree decl, tree init, tree 
*** 2817,2822 ****
--- 2817,2845 ----
  	TREE_USED (decl) = 1;
      }
  
+   /* If the name begins with a *, that's a sign of an asmname attached to
+      a previous declaration.
+      We allow the same name to be specified later and ignore it.  */
+   if (asmspec && IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))[0] == '*')
+     {
+       const char *oldasmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)) + 1;
+ 
+       if (strcmp (asmspec, oldasmname) == 0)
+ 	asmspec=NULL;
+     }
+ 
+   if (asmspec
+       && (TREE_USED (decl) || TREE_ASM_WRITTEN (decl)
+ 	  || (TREE_CODE (decl) == FUNCTION_DECL && DECL_SAVED_TREE (decl))
+ 	  || (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))))
+     {
+       if (TREE_CODE (decl) == FUNCTION_DECL)
+         error ("%HFunction '%D' used before renamed", &DECL_SOURCE_LOCATION (decl), decl);
+       else
+         error ("%HVariable '%D' used before renamed", &DECL_SOURCE_LOCATION (decl), decl);
+       asmspec = NULL;
+     }
+ 
    /* If this is a function and an assembler name is specified, reset DECL_RTL
       so we can give it its new name.  Also, update built_in_decls if it
       was a normal built-in.  */



More information about the Gcc-patches mailing list