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

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).