public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113664] New: False positive warnings with -fno-strict-overflow (-Warray-bounds, -Wstringop-overflow)
@ 2024-01-29 21:50 stefan at bytereef dot org
  2024-01-29 22:01 ` [Bug tree-optimization/113664] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: stefan at bytereef dot org @ 2024-01-29 21:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113664
           Summary: False positive warnings with -fno-strict-overflow
                    (-Warray-bounds, -Wstringop-overflow)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefan at bytereef dot org
  Target Milestone: ---

These false positives only occur in combination with fno-strict-overflow:

================
 -Warray-bounds
================

foo.c
=========================================================
#include <stdio.h>

static char *
f(char *s, int n, char *dot)
{
  switch(n) {
  case 1:
    if (s == dot) {
      *s++ = '.';
    }
    *s++ = '0'; /* fall-through (yes, really!) */
  default:
    if (s == dot) {
      *s++ = '.';
    }
  }

  *s = '\0';
  return s;
}

char *
g(char *s)
{
  return f(s, 1, NULL);
}
=========================================================


$ /home/skrah/gcc/bin/gcc -Wall -O3 -c foo.c
$ /home/skrah/gcc/bin/gcc -Wall -O3 -fno-strict-overflow -c foo.c
In function ‘f’,
    inlined from ‘g’ at foo.c:25:10:
foo.c:11:10: warning: array subscript 0 is outside array bounds of ‘char[0]’
[-Warray-bounds=]
   11 |     *s++ = '0'; /* fall-through (yes, really!) */
      |     ~~~~~^~~~~
In function ‘g’:
cc1: note: source object is likely at address zero



=====================
 -Wstringop-overflow 
=====================

bar.c
=========================================================
#include <stdio.h>

static char *
f(char *s, int n, char *dot)
{
  switch(n) {
  case 1:
    if (s == dot) {
      *s++ = '.';
    }
    *s++ = '0'; /* fall-through (yes, really!) */
  default:
    if (s == dot) {
      *s++ = '.';
    }
  }

  *s = '\0';
  return s;
}

char *
g(char *s)
{
    char sign = '+';
    *s++ = sign;

    return f(s, 1, NULL);
}
=========================================================


$ /home/skrah/gcc/bin/gcc -Wall -O3 -c bar.c
$ /home/skrah/gcc/bin/gcc -Wall -O3 -fno-strict-overflow -c bar.c
In function ‘f’,
    inlined from ‘g’ at bar.c:28:12:
bar.c:11:10: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   11 |     *s++ = '0'; /* fall-through (yes, really!) */
      |     ~~~~~^~~~~
In function ‘g’:
cc1: note: destination object is likely at address zero




Note that a very small change gives a very different warning.

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

end of thread, other threads:[~2024-01-30 11:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 21:50 [Bug c/113664] New: False positive warnings with -fno-strict-overflow (-Warray-bounds, -Wstringop-overflow) stefan at bytereef dot org
2024-01-29 22:01 ` [Bug tree-optimization/113664] " pinskia at gcc dot gnu.org
2024-01-29 22:16 ` stefan at bytereef dot org
2024-01-29 22:19 ` pinskia at gcc dot gnu.org
2024-01-30  8:00 ` rguenth at gcc dot gnu.org
2024-01-30 11:11 ` stefan at bytereef dot org
2024-01-30 11:25 ` stefan at bytereef dot 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).