public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/97628] New: format truncation false positive for O1 and mtune=nocona
@ 2020-10-29 12:42 walter.gcc at wjd dot nu
  2020-10-29 14:16 ` [Bug tree-optimization/97628] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: walter.gcc at wjd dot nu @ 2020-10-29 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97628
           Summary: format truncation false positive for O1 and
                    mtune=nocona
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: walter.gcc at wjd dot nu
  Target Milestone: ---

Created attachment 49468
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49468&action=edit
trimmed down problem from Asterisk say.c

Per the discussion here:
https://gerrit.asterisk.org/c/asterisk/+/14501

I believe there is a bug in gcc 9 where it falsely reports:

  warning: ‘%d’ directive output may be truncated writing
    between 1 and 11 bytes into a region of size 10
    [-Wformat-truncation=]

See the attached example, it only triggers when:

- optimization is 1 or higher
- arch tuning is set to nocona

Example:

$ gcc -O1 -mtune=nocona -S -Wall say2.c
say2.c: In function ‘ast_say_number_full_zh’:
say2.c:37:32: warning: ‘%d’ directive output may be truncated writing between 1
and 11 bytes into a region of size 10 [-Wformat-truncation=]
   37 |             snprintf(buf, 10, "%d", num);
      |                                ^~
say2.c:37:31: note: directive argument in the range [-2147483648, 9]
...

But when omitting either -O1 or -mtune=nocona we do not get this warning.

And if you read the code, you would see that at line 37, num cannot be negative
(because it would've hit a different if-branch).

gcc version is the Ubuntu/Focal one:

    $ gcc --version
    gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0


Cheers,
Walter Doekes
OSSO B.V.

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

end of thread, other threads:[~2020-10-29 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 12:42 [Bug tree-optimization/97628] New: format truncation false positive for O1 and mtune=nocona walter.gcc at wjd dot nu
2020-10-29 14:16 ` [Bug tree-optimization/97628] " msebor at gcc dot gnu.org
2020-10-29 14:27 ` jakub at gcc dot gnu.org
2020-10-29 14:47 ` msebor at gcc dot gnu.org
2020-10-29 14:52 ` jakub at gcc dot gnu.org
2020-10-29 15:11 ` msebor 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).