https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96963
Bug ID: 96963
Summary: -Wstringop-overflow false positive on -O3 or -O2
-ftree-vectorize when assigning consecutive char
struct members
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc_bugzilla at venus dot thegavinli.com
Target Milestone: ---
Created attachment 49194
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49194&action=edit
Test case that triggers bug
Versions affected: 10.2.0 and git master (commit 703bc188f4)
System type: both x86_64-pc-linux-gnu and arm-none-eabi affected
Compilation flags: I tested a couple compilers with the same result:
1) Arch Linux toolchain, configured with: /build/gcc/src/gcc/configure
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
2) Built from git, configured with: ./configure --prefix=/tmp/gcc-master
--disable-multilib
Command lines that trigger bug:
$ gcc sample.c -c -O3
$ gcc sample.c -c -O2 -ftree-vectorize
Code that triggers bug:
struct foo {
int i;
char a;
char b;
};
void heh(char *);
void clr(struct foo *f) {
heh(&f->a);
f->a = 0;
f->b = 0;
}
Output of compiler:
sample.c: In function ‘clr’:
sample.c:11:10: warning: writing 2 bytes into a region of size 1
[-Wstringop-overflow=]
11 | f->a = 0;
| ~^~~
sample.c:3:10: note: at offset 0 to object ‘a’ with size 1 declared here
3 | char a;
| ^
-fdump-tree-optimized:
;; Function clr (clr, funcdef_no=0, decl_uid=1936, cgraph_uid=1,
symbol_order=0)
clr (struct foo * f)
{
char * _1;
[local count: 1073741824]:
_1 = &f_2(D)->a;
heh (_1);
MEM [(char *)f_2(D) + 4B] = { 0, 0 };
return;
}