public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion
@ 2011-08-08  7:16 eggert at gnu dot org
  2011-08-08 10:14 ` [Bug tree-optimization/50021] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eggert at gnu dot org @ 2011-08-08  7:16 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: -Wsuggest-attribute=pure makes obviously-incorrect
                    suggestion
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org


Created attachment 24948
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24948
v.i - input that causes GCC to generate incorrect warning

I ran into this problem when building coreutils (git master) using
GCC 4.6.1, x86-64, on Fedora 14.

For the attached program v.i, "gcc -Wsuggest-attribute=pure -O2 -S v.i" says:

  v.i:3546:1: warning: function might be candidate for attribute 'pure' if it
is known to return normally [-Wsuggest-attribute=pure]

But the function in question is obviously not pure:

  static void
  advance (_Bool f)
  {
    ++pos;
    if (f && pos >= argc)
      beyond ();
  }

as it starts off with a side effect (adding 1 to the static variable 'pos').

Here's the output of "gcc -v -save-temps -Wsuggest-attribute=pure -O2 -S v.i":

  Using built-in specs.
  COLLECT_GCC=gcc
 
COLLECT_LTO_WRAPPER=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
  Target: x86_64-unknown-linux-gnu
  Configured with: ../gcc-4.6.1/configure
--prefix=/home/eggert/opt/Linux-x86_64/gcc-4.6.1 --disable-nls
  Thread model: posix
  gcc version 4.6.1 (GCC) 
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wsuggest-attribute=pure' '-O2' '-S'
'-mtune=generic' '-march=x86-64'
  
/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/cc1
-fpreprocessed v.i -quiet -dumpbase v.i -mtune=generic -march=x86-64 -auxbase v
-O2 -Wsuggest-attribute=pure -version -o v.s
  GNU C (GCC) version 4.6.1 (x86_64-unknown-linux-gnu)
      compiled by GNU C version 4.6.1, GMP version 4.3.1, MPFR version 2.4.2,
MPC version 0.8.1
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  GNU C (GCC) version 4.6.1 (x86_64-unknown-linux-gnu)
      compiled by GNU C version 4.6.1, GMP version 4.3.1, MPFR version 2.4.2,
MPC version 0.8.1
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  Compiler executable checksum: b0a4f47793c670c0e36c6193e4fd175b
  v.i:3546:1: warning: function might be candidate for attribute 'pure' if it
is known to return normally [-Wsuggest-attribute=pure]
 
COMPILER_PATH=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/
 
LIBRARY_PATH=/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/eggert/opt/Linux-x86_64/gcc-4.6.1/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../:/lib/:/usr/lib/
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wsuggest-attribute=pure' '-O2' '-S'
'-mtune=generic' '-march=x86-64'


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

* [Bug tree-optimization/50021] -Wsuggest-attribute=pure makes obviously-incorrect suggestion
  2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
@ 2011-08-08 10:14 ` rguenth at gcc dot gnu.org
  2011-08-08 20:49 ` hubicka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-08 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic, wrong-code
   Last reconfirmed|                            |2011.08.08 10:12:05
          Component|c                           |tree-optimization
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-08 10:12:05 UTC ---
Confirmed.  We suggest 'pure' for the head of the function which was split
by partial inlining.  With -fno-partial-inlining the suggestion is gone.

Honza - we need to make sure to never suggest attributes for clones
(or heads of functions which I guess we are not representing as clone?).

The bug is really bad - and I'd rate this "diagnostic issue" as wrong-code,
as that is what we suggest.


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

* [Bug tree-optimization/50021] -Wsuggest-attribute=pure makes obviously-incorrect suggestion
  2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
  2011-08-08 10:14 ` [Bug tree-optimization/50021] " rguenth at gcc dot gnu.org
@ 2011-08-08 20:49 ` hubicka at gcc dot gnu.org
  2011-08-09  8:28 ` rguenther at suse dot de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2011-08-08 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> 2011-08-08 20:48:51 UTC ---
Yep, we need to mark partial clones and supress warnings there. Do we have way
to work out from DECL if it is a clone? (from callgraph it is bit tricky in
this case when it comes to ltrans partitioning. For sure I can stick flag there
through)

Honza


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

* [Bug tree-optimization/50021] -Wsuggest-attribute=pure makes obviously-incorrect suggestion
  2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
  2011-08-08 10:14 ` [Bug tree-optimization/50021] " rguenth at gcc dot gnu.org
  2011-08-08 20:49 ` hubicka at gcc dot gnu.org
@ 2011-08-09  8:28 ` rguenther at suse dot de
  2012-03-25  2:56 ` bruno at clisp dot org
  2014-09-26 16:11 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenther at suse dot de @ 2011-08-09  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from rguenther at suse dot de <rguenther at suse dot de> 2011-08-09 08:27:16 UTC ---
On Mon, 8 Aug 2011, hubicka at gcc dot gnu.org wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50021
> 
> --- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> 2011-08-08 20:48:51 UTC ---
> Yep, we need to mark partial clones and supress warnings there. Do we have way
> to work out from DECL if it is a clone? (from callgraph it is bit tricky in
> this case when it comes to ltrans partitioning. For sure I can stick flag there
> through)

I'm not sure - I probably would add a decl flag for this (might be useful
for debug info as well).


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

* [Bug tree-optimization/50021] -Wsuggest-attribute=pure makes obviously-incorrect suggestion
  2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
                   ` (2 preceding siblings ...)
  2011-08-09  8:28 ` rguenther at suse dot de
@ 2012-03-25  2:56 ` bruno at clisp dot org
  2014-09-26 16:11 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: bruno at clisp dot org @ 2012-03-25  2:56 UTC (permalink / raw)
  To: gcc-bugs

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

bruno at clisp dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bruno at clisp dot org

--- Comment #4 from bruno at clisp dot org 2012-03-25 01:06:41 UTC ---
Apparently fixed in GCC 4.7.0.gcc -Wsuggest-attribute=pure -O2 -S v.i


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

* [Bug tree-optimization/50021] -Wsuggest-attribute=pure makes obviously-incorrect suggestion
  2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
                   ` (3 preceding siblings ...)
  2012-03-25  2:56 ` bruno at clisp dot org
@ 2014-09-26 16:11 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2014-09-26 16:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50021

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Yep, fixed in 4.7+


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

end of thread, other threads:[~2014-09-26 16:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-08  7:16 [Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion eggert at gnu dot org
2011-08-08 10:14 ` [Bug tree-optimization/50021] " rguenth at gcc dot gnu.org
2011-08-08 20:49 ` hubicka at gcc dot gnu.org
2011-08-09  8:28 ` rguenther at suse dot de
2012-03-25  2:56 ` bruno at clisp dot org
2014-09-26 16:11 ` hubicka at gcc dot gnu.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).