On 6/16/21 11:21 AM, José Rui Faustino de Sousa wrote:
On 16/06/21 16:53, Martin Sebor wrote:
-fstrict-overflow isn't related to the warning or to sprintf (it
controls whether signed integer overflow is considered undefined).

The warning above tells you that if help points to a string that's
255 characters long the snprintf output will be truncated.  This
warning is only issued at level 2 (-Wformat-truncation=2) which
points out more instances of possible truncation than the more
conservative level 1.


These are the flags I use to build gcc:

-O0 -g3 -ggdb3 -gdwarf-4 -fvar-tracking-assignments -fno-omit-frame-pointer -fstrict-overflow -fstack-check

I have been using these flags for more than a year now, it just started failing recently.

Maybe this is due to some other, deeper, issue?

The early sprintf warning pass has been moved recently to run after
the IL has been converted to the SSA form which lets it follow more
logic.  But because few optimizations have been done on the IL at
that point it also results in different warnings than when it runs
later.  In this case, the difference is that the pass now sees a PHI
where before it saw a VAR_DECL and the logic between the two is just
different enough that it makes a difference to the heuristics used
to enable vs disable it.  I don't really think the warning is doing
anything wrong, it just works with limited view of the code at -O0.
Perhaps it might be worth turning off the "maybe" kind of warnings
when optimization is disabled to reduce noise.  Here's a test case
that shows another difference between GCC 11 and trunk (although
this one warns consistently with -O0 and -O2 as well so that's
an improvement):

  char a[7], d[8], *p;

  void f (int i)
  {
    const char *s = i ? a : p;
    __builtin_snprintf (d, sizeof d, "%s x", s);   // trunk warns
  }

Martin


Thank you very much.

Best regards,
José Rui

P.S.- from config.log:

  $ ../gcc-local/configure --prefix=/opt/gcc/gcc-local --enable-debug --enable-checking --enable-valgrind-annotations --disable-multilib CFLAGS= -O0 -g3 -ggdb3 -gdwarf-4 -fvar-tracking-assignments -fno-omit-frame-pointer -fstrict-overflow -fstack-check   CXXFLAGS= -O0 -g3 -ggdb3 -gdwarf-4 -fvar-tracking-assignments -fno-omit-frame-pointer -fstrict-overflow -fstack-check   --enable-languages=c,c++,fortran,lto --no-create --no-recursion


Reply via email to