public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104789] New: [12 Regression] New -Wstringop-overflow false positive since r12-5863-g9354a7d70caef1c9
@ 2022-03-04 16:26 marxin at gcc dot gnu.org
  2022-03-04 16:26 ` [Bug tree-optimization/104789] " marxin at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-03-04 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104789
           Summary: [12 Regression] New -Wstringop-overflow false positive
                    since r12-5863-g9354a7d70caef1c9
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: msebor at gcc dot gnu.org
  Target Milestone: ---

It's originally reported here:
https://github.com/godotengine/godot/issues/58747

$ cat godot-stringop.cpp
#include <cstdint>
#include <cstdio>

uint32_t some_func(const uint32_t components) {
        uint8_t header[8];
        uint32_t header_bytes = 0;
        for (uint32_t i = 0; i < components; i++) {
                header_bytes += 2;
        }
        header_bytes += 2;
        // This works it around, but shouldn't be needed AFAICT.
        //while (header_bytes != 8 && header_bytes % 4 != 0) {
        while (header_bytes % 4 != 0) {
                header[header_bytes++] = 0;
        }
        for (uint32_t i = 0; i < header_bytes; i++) {
                printf("%d\n", header[i]);
        }
        return header_bytes;
}

int main() {
        some_func(1);
        some_func(3);
        return 0;
}

$ g++ godot-stringop.cpp -c -Werror=all -O3
godot-stringop.cpp: In function ‘uint32_t some_func(uint32_t)’:
godot-stringop.cpp:14:40: error: writing 1 byte into a region of size 0
[-Werror=stringop-overflow=]
   14 |                 header[header_bytes++] = 0;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
godot-stringop.cpp:5:17: note: at offset 8 into destination object ‘header’ of
size 8
    5 |         uint8_t header[8];
      |                 ^~~~~~
cc1plus: some warnings being treated as errors

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

end of thread, other threads:[~2023-05-08 12:24 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 16:26 [Bug tree-optimization/104789] New: [12 Regression] New -Wstringop-overflow false positive since r12-5863-g9354a7d70caef1c9 marxin at gcc dot gnu.org
2022-03-04 16:26 ` [Bug tree-optimization/104789] " marxin at gcc dot gnu.org
2022-03-04 16:27 ` marxin at gcc dot gnu.org
2022-03-04 19:54 ` pinskia at gcc dot gnu.org
2022-03-04 19:57 ` pinskia at gcc dot gnu.org
2022-03-07 11:05 ` rverschelde at gmail dot com
2022-03-07 12:05 ` pinskia at gcc dot gnu.org
2022-03-07 12:39 ` rverschelde at gmail dot com
2022-03-07 13:30 ` rverschelde at gmail dot com
2022-03-07 18:10 ` msebor at gcc dot gnu.org
2022-03-07 18:34 ` [Bug tree-optimization/104789] [12 Regression] -Wstringop-overflow false positive at -O3 for an unrolled loop msebor at gcc dot gnu.org
2022-03-09  9:45 ` rguenth at gcc dot gnu.org
2022-03-14 17:35 ` msebor at gcc dot gnu.org
2022-05-06  8:32 ` [Bug tree-optimization/104789] [12/13 " jakub at gcc dot gnu.org
2022-07-26 12:43 ` rguenth at gcc dot gnu.org
2023-05-08 12:24 ` [Bug tree-optimization/104789] [12/13/14 " rguenth 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).