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++ FE patch for attribute alias bug


This testcase works with the C compiler but not the C++ compiler.  Imagine
the extern decl is in a header file.  This makes it very hard to use weak
alias attributes in C++ code.  This testcase was extracted from eCos.
	
extern void foo(void);
void foo(void)  __attribute__ ((weak)) __attribute__ ((alias ("__foo")));
void __foo(void) {}

This was broken by a change from Aldy Hernandez that added the always_inline
attribute.
	http://gcc.gnu.org/ml/gcc-patches/2002-02/msg01367.html
This added a call to decl_attributes inside duplicate_decls.  The problem
with this is that it causes us to reapply the original attributes on newdecl.
This is a problem for attributes that can't be applied twice.  The alias
attribute is such a case.  handle_alias_attribute emits an error if 
DECL_INITIAL is set, and then sets DECL_INITIAL.  If you apply the alias
attribute a second time, you get the error because DECL_INITIAL is already set.

The patch says the only justification for adding the call is to copy the
new always_inline bit from olddecl to newdecl.  However, this bit was dropped
in a later revision in a patch due to a comment from Richard Henderson saying
it was unnecessary.  Since the new always_inline decl bit disappeared, the
call to decl_attributes should too.  This call was never the right way to
solve the problem anyways.  There should have been code added to manually
copy the new always_inline bit from olddecl to newdecl, just like the existing
code that copies DECL_INLINE and DECL_UNINLINABLE.
	
This was tested with an x86 linux make bootstrap and make check.
I have checked in this patch.

2002-10-10  Jim Wilson  <wilson@redhat.com>

	* decl.c (duplicate_decls): Don't call decl_attributes.

Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.943
diff -p -r1.943 decl.c
*** decl.c	9 Oct 2002 21:27:37 -0000	1.943
--- decl.c	10 Oct 2002 22:26:29 -0000
*************** duplicate_decls (newdecl, olddecl)
*** 3422,3428 ****
       except for any that we copy here from the old type.  */
    DECL_ATTRIBUTES (newdecl)
      = (*targetm.merge_decl_attributes) (olddecl, newdecl);
-   decl_attributes (&newdecl, DECL_ATTRIBUTES (newdecl), 0);
  
    if (TREE_CODE (newdecl) == TEMPLATE_DECL)
      {
--- 3422,3427 ----


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