public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/44321] attribute warn_unused_result fails under inlining.
  2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
@ 2010-05-29 11:33 ` davek at gcc dot gnu dot org
  2010-05-29 11:40 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: davek at gcc dot gnu dot org @ 2010-05-29 11:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from davek at gcc dot gnu dot org  2010-05-29 11:33 -------
Created an attachment (id=20771)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20771&action=view)
testcase as per initial comment.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/44321]  New: attribute warn_unused_result fails under inlining.
@ 2010-05-29 11:33 davek at gcc dot gnu dot org
  2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: davek at gcc dot gnu dot org @ 2010-05-29 11:33 UTC (permalink / raw)
  To: gcc-bugs

In the (to-be) attached testcase, GCC warns about an unused result when the
return value of the function is ignored, or cast to void, but it fails to warn
when the cast-to-void is hidden inside an inline function, like so:

$ cat -n wur.c
     1
     2  static inline void ignore_value (int i) { (void) i; }
     3
     4  extern int foo (void) __attribute__ ((warn_unused_result));
     5
     6  void bar1 (void)
     7  {
     8    foo ();
     9  }
    10
    11  void bar2 (void)
    12  {
    13    (void) foo ();
    14  }
    15
    16  void bar3 (void)
    17  {
    18    ignore_value (foo ());
    19  }

$ gcc-4 -c wur.c  -o wur.o --save-temps -W -Wall -Wextra
wur.c: In function 'bar2':
wur.c:13:3: warning: ignoring return value of 'foo', declared with attribute
war
n_unused_result [-Wunused-result]
wur.c: In function 'bar1':
wur.c:8:7: warning: ignoring return value of 'foo', declared with attribute
warn
_unused_result [-Wunused-result]

This happens at all -O levels.  I haven't filled in the host/target/build
triplets because I don't suppose it is in any way specific to any of them.

BTW, it's interesting that the warnings come out in reverse order, is that
supposed to happen?


-- 
           Summary: attribute warn_unused_result fails under inlining.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: davek at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/44321] attribute warn_unused_result fails under inlining.
  2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
  2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
@ 2010-05-29 11:40 ` rguenth at gcc dot gnu dot org
  2010-05-29 17:32 ` bonzini at gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-29 11:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2010-05-29 11:40 -------
You can add

void bar4 (void)
{
  int dummy;
  dummy = foo ();
}

so I'm not sure the ignore_value () function call isn't a use.  In fact
if you externalize that function it is at least a possible use.

Which also raises the question whether (void) is really more "ignoring"
the result than the assignment to a dummy variable.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/44321] attribute warn_unused_result fails under inlining.
  2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
  2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
  2010-05-29 11:40 ` rguenth at gcc dot gnu dot org
@ 2010-05-29 17:32 ` bonzini at gnu dot org
  2010-05-29 17:46 ` rguenth at gcc dot gnu dot org
  2010-05-30  6:43 ` bonzini at gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: bonzini at gnu dot org @ 2010-05-29 17:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bonzini at gnu dot org  2010-05-29 17:32 -------
I don't think this bug is of any use.  Unlike nonnull, unused return values do
not trigger undesirable optimizations and (as far as I can tell) cannot
possibly result in miscompilation.

This bug is indeed about a loophole, and one that could indeed cause some bugs
(even security bugs).  But, fixing it would also make it impossible for many
projects to use -Werror, since they have to deal with the fact that __wur was
used inappropriately by glibc.

Adding another attribute and making __wur overridable BTW would not be a
solution since glibc would certainly switch to the new __really_wur attribute
and we'd be in the same situation.  :-)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/44321] attribute warn_unused_result fails under inlining.
  2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-05-29 17:32 ` bonzini at gnu dot org
@ 2010-05-29 17:46 ` rguenth at gcc dot gnu dot org
  2010-05-30  6:43 ` bonzini at gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-29 17:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2010-05-29 17:46 -------
(In reply to comment #3)
> I don't think this bug is of any use.  Unlike nonnull, unused return values do
> not trigger undesirable optimizations and (as far as I can tell) cannot
> possibly result in miscompilation.
> 
> This bug is indeed about a loophole, and one that could indeed cause some bugs
> (even security bugs).  But, fixing it would also make it impossible for many
> projects to use -Werror, since they have to deal with the fact that __wur was
> used inappropriately by glibc.
> 
> Adding another attribute and making __wur overridable BTW would not be a
> solution since glibc would certainly switch to the new __really_wur attribute
> and we'd be in the same situation.  :-)

True, but if int dummy = foo() works then we can also make (void) foo ()
work.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/44321] attribute warn_unused_result fails under inlining.
  2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-05-29 17:46 ` rguenth at gcc dot gnu dot org
@ 2010-05-30  6:43 ` bonzini at gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: bonzini at gnu dot org @ 2010-05-30  6:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bonzini at gnu dot org  2010-05-30 06:42 -------
Richi, I think we're saying the same thing from two different directions.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44321


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-30  6:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
2010-05-29 11:40 ` rguenth at gcc dot gnu dot org
2010-05-29 17:32 ` bonzini at gnu dot org
2010-05-29 17:46 ` rguenth at gcc dot gnu dot org
2010-05-30  6:43 ` bonzini at gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).