public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marxin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/104789] New: [12 Regression] New -Wstringop-overflow false positive since r12-5863-g9354a7d70caef1c9
Date: Fri, 04 Mar 2022 16:26:50 +0000	[thread overview]
Message-ID: <bug-104789-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-03-04 16:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 16:26 marxin at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104789-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).