From: Dumitru Ceara <dceara@redhat.com>
To: gcc-help@gcc.gnu.org
Subject: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1
Date: Fri, 28 Jan 2022 16:01:36 +0100 [thread overview]
Message-ID: <8d42151f-7be2-4d67-5b46-a83ba55d5c1c@redhat.com> (raw)
Hi everyone,
I think we've hit a false positive warning report when changing some of
our code and using a relatively new gcc version (11.2).
I tried to simplify the reproducer as much as possible and ended up with
test.c below. With gcc 10.3 I don't see this warning, while with gcc
11.1 we seem to hit it.
I can open a bug for this but I was wondering if it's maybe already
known/reported.
Thank you!
Regards,
Dumitru
---
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20210728/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
$ cat test.c
/* Compile with:
* # gcc -g -O2 -c -o test.o test.c
* test.c: In function ‘foo’:
* test.c:47:5: warning: ‘memcpy’ writing 6 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
* 47 | memcpy(h2 + 1, &somedata[0], 6);
* | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* # gcc -v
* [...]
* gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
*/
#include <string.h>
#include <stdint.h>
static char somedata[1024];
struct pkt {
void *base_;
uint16_t l4_ofs;
};
struct hdr1 {
uint32_t h11;
};
struct hdr2 {
uint32_t h21;
};
extern void pkt_bar(struct pkt *);
void foo(void)
{
uint64_t stub[1024 / 8];
struct pkt p;
p.base_ = &stub[0];
p.l4_ofs = UINT16_MAX;
size_t size = 8;
/* If I comment the next line out the warning goes away. */
pkt_bar(&p);
void *data = (char *) p.base_;
memset(data, 0, size);
struct hdr1 *h1 = data;
p.l4_ofs = (uintptr_t)(h1 + 1) - (uintptr_t)p.base_;
void *l4data = p.l4_ofs != UINT16_MAX ? (char *) p.base_ + p.l4_ofs : NULL;
struct hdr2 *h2 = l4data;
memcpy(h2 + 1, &somedata[0], 6);
h2->h21 = 0;
}
next reply other threads:[~2022-01-28 15:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 15:01 Dumitru Ceara [this message]
2022-01-28 15:27 ` Segher Boessenkool
2022-01-28 16:16 ` Dumitru Ceara
2022-01-28 17:37 ` Segher Boessenkool
2022-01-31 21:49 ` Martin Sebor
2022-01-31 22:01 ` Segher Boessenkool
2022-02-01 8:21 ` Jonathan Wakely
2022-02-01 5:18 ` Richard Sandiford
2022-02-01 14:42 ` Segher Boessenkool
2022-02-01 23:54 ` Martin Sebor
2022-02-02 10:12 ` Jonathan Wakely
2022-02-02 18:33 ` Segher Boessenkool
2022-02-02 20:44 ` Jonathan Wakely
2022-02-02 18:23 ` Segher Boessenkool
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=8d42151f-7be2-4d67-5b46-a83ba55d5c1c@redhat.com \
--to=dceara@redhat.com \
--cc=gcc-help@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).