Message ID | 20110127005946.GC2412@kam.mff.cuni.cz |
---|---|
State | New |
Headers | show |
On Thu, Jan 27, 2011 at 01:59:46AM +0100, Jan Hubicka wrote: > Hi, > the testcase cause ICE in verifier on function that is both defined and has > weakref alias. This seems to be nonsense, so it is better to warn on it and > ignore the weakref > > Bootstrapped/regtested x86_64-linux, OK? Honza, This change appears to cause gcc.dg/attr-weakref-3.c to ICE on x86_64-apple-darwin10 at both -m32 and -m64. Executing on host: /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20110126/gcc/testsuite/gcc.dg/attr-weakref-3.c -ansi -pedantic-errors -S -m32 -o attr-weakref-3.s (timeout = 300) /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20110126/gcc/testsuite/gcc.dg/attr-weakref-3.c:3:1: internal compiler error: Segmentation fault [MacPro:~/weakref] howarth% gdb /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/cc1 ... (gdb) r -quiet -v -imultilib i386 -iprefix /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/../lib/gcc/x86_64-apple-darwin10.7.0/4.6.0/ -isystem /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/include -isystem /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/include-fixed -D__DYNAMIC__ /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20110126/gcc/testsuite/gcc.dg/attr-weakref-3.c -fPIC -quiet -dumpbase attr-weakref-3.c -mmacosx-version-min=10.6.7 -m32 -mtune=core2 -auxbase-strip attr-weakref-3.s -pedantic-errors -ansi -version -o attr-weakref-3.s ... Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 process_function_and_variable_attributes (first=<value temporarily unavailable, due to optimizations>, first_var=0x0) at ../../gcc-4.6-20110126/gcc/cgraphunit.c:901 901 warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, (gdb) bt #0 process_function_and_variable_attributes (first=<value temporarily unavailable, due to optimizations>, first_var=0x0) at ../../gcc-4.6-20110126/gcc/cgraphunit.c:901 #1 0x00000001007cd07b in cgraph_analyze_functions () at ../../gcc-4.6-20110126/gcc/cgraphunit.c:926 (gdb) Jack > > Honza > > PR middle-end/46949 > * cgraphunit.c (process_function_and_variable_attributes): Warn on > defined weakrefs. > * gcc.dg/attr-weakref-4.c: New testcase. > Index: cgraphunit.c > =================================================================== > --- cgraphunit.c (revision 169294) > +++ cgraphunit.c (working copy) > @@ -860,6 +860,14 @@ process_function_and_variable_attributes > else if (node->local.finalized) > cgraph_mark_needed_node (node); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && node->local.finalized) > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because function is defined"); > + DECL_WEAK (decl) = 0; > + } > process_common_attributes (decl); > } > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) > @@ -887,6 +895,14 @@ process_function_and_variable_attributes > else if (vnode->finalized) > varpool_mark_needed_node (vnode); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && vnode->finalized) > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because variable is initialized"); > + DECL_WEAK (decl) = 0; > + } > process_common_attributes (decl); > } > } > Index: testsuite/gcc.dg/attr-weakref-4.c > =================================================================== > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) > +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) > @@ -0,0 +1,3 @@ > +/* { dg-do compile } */ > +/* { dg-require-weak "" } */ > +static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */
On Thu, Jan 27, 2011 at 1:59 AM, Jan Hubicka <hubicka@ucw.cz> wrote: > Hi, > the testcase cause ICE in verifier on function that is both defined and has > weakref alias. This seems to be nonsense, so it is better to warn on it and > ignore the weakref > > Bootstrapped/regtested x86_64-linux, OK? > > Honza > > PR middle-end/46949 > * cgraphunit.c (process_function_and_variable_attributes): Warn on > defined weakrefs. > * gcc.dg/attr-weakref-4.c: New testcase. > Index: cgraphunit.c > =================================================================== > --- cgraphunit.c (revision 169294) > +++ cgraphunit.c (working copy) > @@ -860,6 +860,14 @@ process_function_and_variable_attributes > else if (node->local.finalized) > cgraph_mark_needed_node (node); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && node->local.finalized) > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because function is defined"); > + DECL_WEAK (decl) = 0; > + } > process_common_attributes (decl); > } > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) > @@ -887,6 +895,14 @@ process_function_and_variable_attributes > else if (vnode->finalized) > varpool_mark_needed_node (vnode); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && vnode->finalized) your testcase has a function and you test vnode? > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because variable is initialized"); > + DECL_WEAK (decl) = 0; What if the function has __attribute__((weak,weakref))? Then the above is wrong as we want to retain the weak but not the weakref. Richard. > + } > process_common_attributes (decl); > } > } > Index: testsuite/gcc.dg/attr-weakref-4.c > =================================================================== > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) > +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) > @@ -0,0 +1,3 @@ > +/* { dg-do compile } */ > +/* { dg-require-weak "" } */ > +static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ >
> > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) > > @@ -887,6 +895,14 @@ process_function_and_variable_attributes > > else if (vnode->finalized) > > varpool_mark_needed_node (vnode); > > } > > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > > + && vnode->finalized) > > your testcase has a function and you test vnode? Yes, there is typo. I fixed it and also added DECL_INITIAL(decl) != NULL to handle darwin that finalize BSS. > > > + { > > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > > + "%<weakref%> attribute ignored" > > + " because variable is initialized"); > > + DECL_WEAK (decl) = 0; > > What if the function has __attribute__((weak,weakref))? Then the > above is wrong as we want to retain the weak but not the weakref. You can't have this, since weak is allowed only on public, while weakref only on static vars. Honza > > Richard. > > > + } > > process_common_attributes (decl); > > } > > } > > Index: testsuite/gcc.dg/attr-weakref-4.c > > =================================================================== > > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) > > +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) > > @@ -0,0 +1,3 @@ > > +/* { dg-do compile } */ > > +/* { dg-require-weak "" } */ > > +static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ > >
2011/1/27 Jan Hubicka <hubicka@ucw.cz>: >> > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) >> > @@ -887,6 +895,14 @@ process_function_and_variable_attributes >> > else if (vnode->finalized) >> > varpool_mark_needed_node (vnode); >> > } >> > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) >> > + && vnode->finalized) >> >> your testcase has a function and you test vnode? > > Yes, there is typo. I fixed it and also added DECL_INITIAL(decl) != NULL > to handle darwin that finalize BSS. finalize BSS?! So we accept static int bss __attribute__((weakref)) = 0; ? How's that not a definition? ;) >> >> > + { >> > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, >> > + "%<weakref%> attribute ignored" >> > + " because variable is initialized"); >> > + DECL_WEAK (decl) = 0; >> >> What if the function has __attribute__((weak,weakref))? Then the >> above is wrong as we want to retain the weak but not the weakref. > > You can't have this, since weak is allowed only on public, while weakref > only on static vars. > > Honza >> >> Richard. >> >> > + } >> > process_common_attributes (decl); >> > } >> > } >> > Index: testsuite/gcc.dg/attr-weakref-4.c >> > =================================================================== >> > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) >> > +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) >> > @@ -0,0 +1,3 @@ >> > +/* { dg-do compile } */ >> > +/* { dg-require-weak "" } */ >> > +static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ >> > >
On 27 Jan 2011, at 11:25, Richard Guenther wrote: > 2011/1/27 Jan Hubicka <hubicka@ucw.cz>: >>>> for (vnode = varpool_nodes; vnode != first_var; vnode = vnode- >>>> >next) >>>> @@ -887,6 +895,14 @@ process_function_and_variable_attributes >>>> else if (vnode->finalized) >>>> varpool_mark_needed_node (vnode); >>>> } >>>> + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) >>>> + && vnode->finalized) >>> >>> your testcase has a function and you test vnode? >> >> Yes, there is typo. I fixed it and also added DECL_INITIAL(decl) != >> NULL >> to handle darwin that finalize BSS. > > finalize BSS?! where do we do this? If it is in the case of ObjC meta-data - then it is possible that the reason is that the target-specific section choice never gets called because of: varasm.c (get_variable_section): if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl) && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) && bss_initializer_p (decl)) { if (!TREE_PUBLIC (decl)) return lcomm_section; if (bss_noswitch_section) return bss_noswitch_section; } which means we end up with meta-data appearing in BSS -- I've got a fix for this as part of a patch-in-progress for ObjC m64 > So we accept > > static int bss __attribute__((weakref)) = 0; > > ? How's that not a definition? ;) if that's not the case in point, then what are we doing wrong? (and I'll try and fix it) Iain > >>> >>>> + { >>>> + warning_at (DECL_SOURCE_LOCATION (node->decl), >>>> OPT_Wattributes, >>>> + "%<weakref%> attribute ignored" >>>> + " because variable is initialized"); >>>> + DECL_WEAK (decl) = 0; >>> >>> What if the function has __attribute__((weak,weakref))? Then the >>> above is wrong as we want to retain the weak but not the weakref. >> >> You can't have this, since weak is allowed only on public, while >> weakref >> only on static vars. >> >> Honza >>> >>> Richard. >>> >>>> + } >>>> process_common_attributes (decl); >>>> } >>>> } >>>> Index: testsuite/gcc.dg/attr-weakref-4.c >>>> =================================================================== >>>> --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) >>>> +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) >>>> @@ -0,0 +1,3 @@ >>>> +/* { dg-do compile } */ >>>> +/* { dg-require-weak "" } */ >>>> +static void __attribute__((weakref("bar"))) foo(void) { } /* >>>> { dg-warning "attribute ignored because function is defined" } */ >>>> >>
On 27 Jan 2011, at 11:35, IainS wrote: > > On 27 Jan 2011, at 11:25, Richard Guenther wrote: > >> 2011/1/27 Jan Hubicka <hubicka@ucw.cz>: >>>>> for (vnode = varpool_nodes; vnode != first_var; vnode = vnode- >>>>> >next) >>>>> @@ -887,6 +895,14 @@ process_function_and_variable_attributes >>>>> else if (vnode->finalized) >>>>> varpool_mark_needed_node (vnode); >>>>> } >>>>> + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) >>>>> + && vnode->finalized) >>>> >>>> your testcase has a function and you test vnode? >>> >>> Yes, there is typo. I fixed it and also added DECL_INITIAL(decl) ! >>> = NULL >>> to handle darwin that finalize BSS. >> >> finalize BSS?! > > where do we do this? > > If it is in the case of ObjC meta-data - then it is possible that > the reason is that the target-specific section choice never gets > called because of: > > varasm.c (get_variable_section): > > if (ADDR_SPACE_GENERIC_P (as) > && !DECL_THREAD_LOCAL_P (decl) > && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) > && bss_initializer_p (decl)) > { > if (!TREE_PUBLIC (decl)) > return lcomm_section; > if (bss_noswitch_section) > return bss_noswitch_section; > } > > which means we end up with meta-data appearing in BSS -- I've got a > fix for this as part of a patch-in-progress for ObjC m64 > >> So we accept >> >> static int bss __attribute__((weakref)) = 0; >> >> ? How's that not a definition? ;) > > > if that's not the case in point, then what are we doing wrong? (and > I'll try and fix it) see also an un-reviewed RFC http://gcc.gnu.org/ml/gcc-patches/2010-11/msg01469.html > > Iain > > >> >>>> >>>>> + { >>>>> + warning_at (DECL_SOURCE_LOCATION (node->decl), >>>>> OPT_Wattributes, >>>>> + "%<weakref%> attribute ignored" >>>>> + " because variable is initialized"); >>>>> + DECL_WEAK (decl) = 0; >>>> >>>> What if the function has __attribute__((weak,weakref))? Then the >>>> above is wrong as we want to retain the weak but not the weakref. >>> >>> You can't have this, since weak is allowed only on public, while >>> weakref >>> only on static vars. >>> >>> Honza >>>> >>>> Richard. >>>> >>>>> + } >>>>> process_common_attributes (decl); >>>>> } >>>>> } >>>>> Index: testsuite/gcc.dg/attr-weakref-4.c >>>>> = >>>>> ================================================================== >>>>> --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) >>>>> +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) >>>>> @@ -0,0 +1,3 @@ >>>>> +/* { dg-do compile } */ >>>>> +/* { dg-require-weak "" } */ >>>>> +static void __attribute__((weakref("bar"))) foo(void) { } /* >>>>> { dg-warning "attribute ignored because function is defined" } */ >>>>> >>> >
> > static int bss __attribute__((weakref)) = 0; > > ? How's that not a definition? ;) This case is diagnose as definition (DECL_INITIAL is non-NULL). Previous patch was bogusly warning at static int bss __attribute__((weakref)); Even these vars are finalized, it is not darwin specific. I confused myself. However we get double warning, this is because one needs to use DECL_ATTRIBUTES (decl) = remove_attribute (...) instead of just remove_attribute to properly update linked list. Here is updated patch, it also fixes attribute removal in my previous patch. Bootstrapped/regtested x86_64-linux, OK? Honza * cgraphunit.c (process_common_attributes): Fix use of remove_attribute. (process_function_and_variable_attributes): Check defined weakrefs. * gcc.dg/attr-weakref-4.c: New testcase Index: cgraphunit.c =================================================================== *** cgraphunit.c (revision 169294) --- cgraphunit.c (working copy) *************** process_common_attributes (tree decl) *** 804,810 **** "%<weakref%> attribute should be accompanied with" " an %<alias%> attribute"); DECL_WEAK (decl) = 0; ! remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); } } --- 804,811 ---- "%<weakref%> attribute should be accompanied with" " an %<alias%> attribute"); DECL_WEAK (decl) = 0; ! DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", ! DECL_ATTRIBUTES (decl)); } } *************** process_function_and_variable_attributes *** 860,865 **** --- 861,876 ---- else if (node->local.finalized) cgraph_mark_needed_node (node); } + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) + && node->local.finalized) + { + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "%<weakref%> attribute ignored" + " because function is defined"); + DECL_WEAK (decl) = 0; + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", + DECL_ATTRIBUTES (decl)); + } process_common_attributes (decl); } for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) *************** process_function_and_variable_attributes *** 887,892 **** --- 898,914 ---- else if (vnode->finalized) varpool_mark_needed_node (vnode); } + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) + && vnode->finalized + && DECL_INITIAL (decl)) + { + warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes, + "%<weakref%> attribute ignored" + " because variable is initialized"); + DECL_WEAK (decl) = 0; + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", + DECL_ATTRIBUTES (decl)); + } process_common_attributes (decl); } } Index: testsuite/gcc.dg/attr-weakref-4.c =================================================================== *** testsuite/gcc.dg/attr-weakref-4.c (revision 0) --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) *************** *** 0 **** --- 1,4 ---- + /* { dg-do compile } */ + /* { dg-require-weak "" } */ + static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ + static int __attribute__((weakref)) a=0; /* { dg-warning "attribute ignored because variable is initialized" } */
On Thu, Jan 27, 2011 at 2:16 PM, Jan Hubicka <hubicka@ucw.cz> wrote: >> >> static int bss __attribute__((weakref)) = 0; >> >> ? How's that not a definition? ;) > > This case is diagnose as definition (DECL_INITIAL is non-NULL). Previous patch > was bogusly warning at > static int bss __attribute__((weakref)); > Even these vars are finalized, it is not darwin specific. I confused myself. > > However we get double warning, this is because one needs to use > DECL_ATTRIBUTES (decl) = remove_attribute (...) > instead of just remove_attribute to properly update linked list. > > Here is updated patch, it also fixes attribute removal in my previous patch. > > Bootstrapped/regtested x86_64-linux, > OK? Ok. Thanks, Richard. > Honza > > * cgraphunit.c (process_common_attributes): Fix use of remove_attribute. > (process_function_and_variable_attributes): Check defined weakrefs. > * gcc.dg/attr-weakref-4.c: New testcase > Index: cgraphunit.c > =================================================================== > *** cgraphunit.c (revision 169294) > --- cgraphunit.c (working copy) > *************** process_common_attributes (tree decl) > *** 804,810 **** > "%<weakref%> attribute should be accompanied with" > " an %<alias%> attribute"); > DECL_WEAK (decl) = 0; > ! remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); > } > } > > --- 804,811 ---- > "%<weakref%> attribute should be accompanied with" > " an %<alias%> attribute"); > DECL_WEAK (decl) = 0; > ! DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > ! DECL_ATTRIBUTES (decl)); > } > } > > *************** process_function_and_variable_attributes > *** 860,865 **** > --- 861,876 ---- > else if (node->local.finalized) > cgraph_mark_needed_node (node); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && node->local.finalized) > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because function is defined"); > + DECL_WEAK (decl) = 0; > + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > + DECL_ATTRIBUTES (decl)); > + } > process_common_attributes (decl); > } > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) > *************** process_function_and_variable_attributes > *** 887,892 **** > --- 898,914 ---- > else if (vnode->finalized) > varpool_mark_needed_node (vnode); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && vnode->finalized > + && DECL_INITIAL (decl)) > + { > + warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because variable is initialized"); > + DECL_WEAK (decl) = 0; > + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > + DECL_ATTRIBUTES (decl)); > + } > process_common_attributes (decl); > } > } > Index: testsuite/gcc.dg/attr-weakref-4.c > =================================================================== > *** testsuite/gcc.dg/attr-weakref-4.c (revision 0) > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) > *************** > *** 0 **** > --- 1,4 ---- > + /* { dg-do compile } */ > + /* { dg-require-weak "" } */ > + static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ > + static int __attribute__((weakref)) a=0; /* { dg-warning "attribute ignored because variable is initialized" } */ >
On Thu, Jan 27, 2011 at 02:16:00PM +0100, Jan Hubicka wrote: > > > > static int bss __attribute__((weakref)) = 0; > > > > ? How's that not a definition? ;) > > This case is diagnose as definition (DECL_INITIAL is non-NULL). Previous patch > was bogusly warning at > static int bss __attribute__((weakref)); > Even these vars are finalized, it is not darwin specific. I confused myself. > > However we get double warning, this is because one needs to use > DECL_ATTRIBUTES (decl) = remove_attribute (...) > instead of just remove_attribute to properly update linked list. > > Here is updated patch, it also fixes attribute removal in my previous patch. Honza, Bootstrap and regtested on x86_64-apple-darwin10 at -m32/-m64 without failures. Jack > > Bootstrapped/regtested x86_64-linux, > OK? > Honza > > * cgraphunit.c (process_common_attributes): Fix use of remove_attribute. > (process_function_and_variable_attributes): Check defined weakrefs. > * gcc.dg/attr-weakref-4.c: New testcase > Index: cgraphunit.c > =================================================================== > *** cgraphunit.c (revision 169294) > --- cgraphunit.c (working copy) > *************** process_common_attributes (tree decl) > *** 804,810 **** > "%<weakref%> attribute should be accompanied with" > " an %<alias%> attribute"); > DECL_WEAK (decl) = 0; > ! remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); > } > } > > --- 804,811 ---- > "%<weakref%> attribute should be accompanied with" > " an %<alias%> attribute"); > DECL_WEAK (decl) = 0; > ! DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > ! DECL_ATTRIBUTES (decl)); > } > } > > *************** process_function_and_variable_attributes > *** 860,865 **** > --- 861,876 ---- > else if (node->local.finalized) > cgraph_mark_needed_node (node); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && node->local.finalized) > + { > + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because function is defined"); > + DECL_WEAK (decl) = 0; > + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > + DECL_ATTRIBUTES (decl)); > + } > process_common_attributes (decl); > } > for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) > *************** process_function_and_variable_attributes > *** 887,892 **** > --- 898,914 ---- > else if (vnode->finalized) > varpool_mark_needed_node (vnode); > } > + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) > + && vnode->finalized > + && DECL_INITIAL (decl)) > + { > + warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes, > + "%<weakref%> attribute ignored" > + " because variable is initialized"); > + DECL_WEAK (decl) = 0; > + DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", > + DECL_ATTRIBUTES (decl)); > + } > process_common_attributes (decl); > } > } > Index: testsuite/gcc.dg/attr-weakref-4.c > =================================================================== > *** testsuite/gcc.dg/attr-weakref-4.c (revision 0) > --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) > *************** > *** 0 **** > --- 1,4 ---- > + /* { dg-do compile } */ > + /* { dg-require-weak "" } */ > + static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */ > + static int __attribute__((weakref)) a=0; /* { dg-warning "attribute ignored because variable is initialized" } */
Index: cgraphunit.c =================================================================== --- cgraphunit.c (revision 169294) +++ cgraphunit.c (working copy) @@ -860,6 +860,14 @@ process_function_and_variable_attributes else if (node->local.finalized) cgraph_mark_needed_node (node); } + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) + && node->local.finalized) + { + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "%<weakref%> attribute ignored" + " because function is defined"); + DECL_WEAK (decl) = 0; + } process_common_attributes (decl); } for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) @@ -887,6 +895,14 @@ process_function_and_variable_attributes else if (vnode->finalized) varpool_mark_needed_node (vnode); } + if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)) + && vnode->finalized) + { + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "%<weakref%> attribute ignored" + " because variable is initialized"); + DECL_WEAK (decl) = 0; + } process_common_attributes (decl); } } Index: testsuite/gcc.dg/attr-weakref-4.c =================================================================== --- testsuite/gcc.dg/attr-weakref-4.c (revision 0) +++ testsuite/gcc.dg/attr-weakref-4.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-require-weak "" } */ +static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */