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]

Re: #pragma weak is broken in 3.1, partail fix


On Sat, May 25, 2002 at 10:55:38AM +0200, Marc Espie wrote:
> * one is structural:   I don't understand how new code to handle #pragma
> weak could have been written and never even TESTED on any testcase before
> being committed.

I thought there were tests for this.  Clearly not.  Rectified.

> * the code that handles attribute lists is exceptionally brittle. It
> shouldn't matter in which order alias/weak attributes are declared. Well,
> right now it does.

No it doesn't.  Why do you say this?

> 	c-pragma.c (apply_pragma_weak):  Rearrange attribute building to work.

I've applied this one instead, since yours doesn't handle
the f4 case properly.


r~


        * c-pragma.c (apply_pragma_weak): Convert value identifier to
        string for decl_attributes.
        (handle_pragma_weak): Call assemble_alias if we're modifying
        an existing decl.

Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.51
diff -c -p -d -r1.51 c-pragma.c
*** c-pragma.c	25 May 2002 22:01:42 -0000	1.51
--- c-pragma.c	26 May 2002 03:22:09 -0000
*************** apply_pragma_weak (decl, value)
*** 283,291 ****
       tree decl, value;
  {
    if (value)
!     decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
! 				             build_tree_list (NULL, value)),
! 		     0);
    if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
        && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
      warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
--- 283,296 ----
       tree decl, value;
  {
    if (value)
!     {
!       value = build_string (IDENTIFIER_LENGTH (value),
! 			    IDENTIFIER_POINTER (value));
!       decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
! 					       build_tree_list (NULL, value)),
! 		       0);
!     }
! 
    if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
        && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
      warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
*************** handle_pragma_weak (dummy)
*** 342,348 ****
  
    decl = identifier_global_value (name);
    if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
!     apply_pragma_weak (decl, value);
    else
      pending_weaks = tree_cons (name, value, pending_weaks);
  }
--- 347,357 ----
  
    decl = identifier_global_value (name);
    if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
!     {
!       apply_pragma_weak (decl, value);
!       if (value)
! 	assemble_alias (decl, value);
!     }
    else
      pending_weaks = tree_cons (name, value, pending_weaks);
  }
Index: testsuite/gcc.dg/weak-9.c
===================================================================
RCS file: testsuite/gcc.dg/weak-9.c
diff -N testsuite/gcc.dg/weak-9.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/weak-9.c	26 May 2002 03:22:10 -0000
***************
*** 0 ****
--- 1,28 ----
+ /* { dg-do compile } */
+ /* { dg-options "-fno-common" } */
+ 
+ /* COFF does not support weak, and dg doesn't support UNSUPPORTED.  */
+ /* { dg-do compile { xfail *-*-coff i?86-pc-cygwin h8300-*-hms } } */
+ 
+ /* { dg-final { global target_triplet } } */
+ /* { dg-final { if [string match h8300-*-hms $target_triplet ] {return} } } */
+ /* { dg-final { if [string match i?86-pc-cygwin $target_triplet ] {return} } } *
+ /
+ /* { dg-final { if [string match *-*-coff $target_triplet ] {return} } } */
+ /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f1" } } */
+ /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f2" } } */
+ /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f3" } } */
+ /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f4" } } */
+ /* { dg-final { scan-assembler "notf1" } } */
+ /* { dg-final { scan-assembler "notf2" } } */
+ /* { dg-final { scan-assembler "notf3" } } */
+ /* { dg-final { scan-assembler "notf4" } } */
+ 
+ void f1() __attribute__((weak, alias("notf1")));
+ void f2() __attribute__((alias("notf2"), weak));
+ 
+ #pragma weak f3=notf3
+ void f3();
+ 
+ void f4();
+ #pragma weak f4=notf4


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