[Patch] PR c/7490

Philippe Trebuchet Philippe.Trebuchet@sophia.inria.fr
Tue Nov 26 06:17:00 GMT 2002


Hi, 
the testcase reflect what I have understood of the meaning of alias (and is
 also the one given in the PR :-)) ) Indeed in the manual it is said
that attribute are emited during declaration, I also found that word
of the manual rather vague "alias attribute cause the declaration to
be emitted as an alias for another symbol which must be specified...
".
This also result in an ICE without the patch.
void foo()
 {
     auto void BAR() {};
     auto void bar () __attribute__ ((alias ("BAR")));
     bar();
}

Right now my patch does not check anything for the symbol the alias is
emitted on, and emit it for the most nested function whose name match
the symbol given or for an external function if it does not find
any. This is the behaviour of gcc up to 2.95 and allows separate
compilation using alias. Should I update my patch for a diagnostic to
be emitted in case no prior valid declaration for the symbol is found?

Something like this seems closer to what Richard was saying and
preserve the existing behaviour:

Index: gcc/ChangeLog
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/ChangeLog,v
retrieving revision 1.15936
diff -c -p -3 -r1.15936 ChangeLog
*** gcc/ChangeLog       18 Nov 2002 23:21:27 -0000      1.15936
--- gcc/ChangeLog       26 Nov 2002 13:45:55 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2002-11-20  Philippe Trebuchet   <ptrebuc@farewell.inria.fr>
+ 
+       * c-semantics.c (genrtl_scope_stmt): Fix local alias Handling
+ 
+       
  2002-11-18  Steve Ellcey  <sje@cup.hp.com>
  
        * config/ia64/hpux_longdouble.h (FIXUNS_TRUNCTFSI2_LIBCALL): New.
Index: gcc/c-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.390
diff -c -p -3 -r1.390 c-common.c
*** gcc/c-common.c      31 Oct 2002 06:57:28 -0000      1.390
--- gcc/c-common.c      26 Nov 2002 13:45:55 -0000
*************** handle_alias_attribute (node, name, args
*** 5842,5855 ****
          *no_add_attrs = true;
          return NULL_TREE;
        }
!       id = get_identifier (TREE_STRING_POINTER (id));
!       /* This counts as a use of the object pointed to.  */
!       TREE_USED (id) = 1;
! 
!       if (TREE_CODE (decl) == FUNCTION_DECL)
!       DECL_INITIAL (decl) = error_mark_node;
!       else
!       DECL_EXTERNAL (decl) = 0;
      }
    else
      {
--- 5842,5858 ----
          *no_add_attrs = true;
          return NULL_TREE;
        }
!       id = maybe_get_identifier (TREE_STRING_POINTER (id));
!       if(id!=NULL_TREE)
!       {
!         /* This counts as a use of the object pointed to.  */
!         TREE_USED (id) = 1;
!         
!         if (TREE_CODE (decl) == FUNCTION_DECL)
!           DECL_INITIAL (decl) = error_mark_node;
!         else
!           DECL_EXTERNAL (decl) = 0;
!       }
      }
    else
      {
Index: gcc/c-semantics.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-semantics.c,v
retrieving revision 1.47
diff -c -p -3 -r1.47 c-semantics.c
*** gcc/c-semantics.c   22 Sep 2002 02:03:15 -0000      1.47
--- gcc/c-semantics.c   26 Nov 2002 13:45:55 -0000
*************** genrtl_scope_stmt (t)
*** 620,628 ****
              && !TREE_ASM_WRITTEN (fn)
              && TREE_ADDRESSABLE (fn))
            {
!             push_function_context ();
!             output_inline_function (fn);
!             pop_function_context ();

            }
        }
      }
--- 620,651 ----
              && !TREE_ASM_WRITTEN (fn)
              && TREE_ADDRESSABLE (fn))
            {
!             tree alias,tmp;
!             alias = lookup_attribute ("alias", DECL_ATTRIBUTES (fn));
!             if (alias)
!               {
!                 alias = TREE_VALUE (TREE_VALUE (alias));
!                 tmp = maybe_get_identifier (TREE_STRING_POINTER (alias));
!                 if(tmp!=NULL_TREE)
!                   assemble_alias (fn, tmp);
!                 else
!                   {
!                     warning("no declaration of `%s' to be aliased",
!                             TREE_STRING_POINTER (alias));
!                     warning("defaulting to extern");
!                     tmp=get_identifier (TREE_STRING_POINTER (alias));
!                     assemble_alias (fn, tmp);
!                   }
!               }
!             else if (DECL_SAVED_INSNS (fn) != NULL)
!                 {
!                   push_function_context ();
!                   output_inline_function (fn);
!                   pop_function_context ();
!                 }
!             else 
!               error ("no definition for auto nested function `%s'",
!                      IDENTIFIER_POINTER (DECL_NAME (fn)));
            }
        }
      }



More information about the Gcc-patches mailing list