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

            Bug ID: 79062
           Summary: -Wformat-length warnings disabled by -flto
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following enhanced test case shows that with r244326 committed to resolve
bug 78768, even though the gimple-ssa-sprintf pass seems to run with -flto,
-Wformat-length (and likely -Wformat-truncation) still doesn't work for some
reason.

$ (set -x; for o in '' '-flto'; do /build/gcc-svn/gcc/xgcc -B
/build/gcc-svn/gcc -O2 -Wall -Wextra -Wpedantic -Walloca-larger-than=1
-Wformat-length=1 $o -fpic -shared -o foo.so -fdump-tree-optimized t.c; cat
t.c.*.optimized; done)
+ for o in ''\'''\''' ''\''-flto'\'''
+ /build/gcc-svn/gcc/xgcc -B /build/gcc-svn/gcc -O2 -Wall -Wextra -Wpedantic
-Walloca-larger-than=1 -Wformat-length=1 -fpic -shared -o foo.so
-fdump-tree-optimized t.c
t.c: In function ‘f’:
t.c:3:9: warning: argument to ‘alloca’ is too large [-Walloca-larger-than=]
   char *d = (char *)__builtin_alloca (2);
         ^
t.c:3:9: note: limit is 1 bytes, but argument is 2
t.c:4:33: warning: ‘%i’ directive writing 3 bytes into a region of size 2
[-Wformat-length=]
   return __builtin_sprintf (d, "%i", 123);
                                 ^~
t.c:4:10: note: format output 4 bytes into a destination of size 2
   return __builtin_sprintf (d, "%i", 123);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ cat t.c.227t.optimized

;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f ()
{
  char * d;
  int _5;

  <bb 2> [100.00%]:
  d_3 = __builtin_alloca (2);
  _5 = __builtin_sprintf (d_3, "%i", 123);
  return _5;

}



;; Function g (g, funcdef_no=1, decl_uid=1799, cgraph_uid=1, symbol_order=1)

g ()
{
  <bb 2> [100.00%]:
  return 3;

}


+ for o in ''\'''\''' ''\''-flto'\'''
+ /build/gcc-svn/gcc/xgcc -B /build/gcc-svn/gcc -O2 -Wall -Wextra -Wpedantic
-Walloca-larger-than=1 -Wformat-length=1 -flto -fpic -shared -o foo.so
-fdump-tree-optimized t.c
t.c: In function ‘f’:
t.c:3:9: warning: argument to ‘alloca’ is too large [-Walloca-larger-than=]
   char *d = (char *)__builtin_alloca (2);
         ^
t.c:3:9: note: limit is 1 bytes, but argument is 2
+ cat t.c.227t.optimized

;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f ()
{
  char * d;
  int _5;

  <bb 2> [100.00%]:
  d_3 = __builtin_alloca (2);
  _5 = __builtin_sprintf (d_3, "%i", 123);
  return _5;

}



;; Function g (g, funcdef_no=1, decl_uid=1799, cgraph_uid=1, symbol_order=1)

g ()
{
  <bb 2> [100.00%]:
  return 3;

}

Reply via email to