[Bug c/50021] New: -Wsuggest-attribute=pure makes obviously-incorrect suggestion

eggert at gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Aug 8 07:16:00 GMT 2011


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'



More information about the Gcc-bugs mailing list