On Wed, 24 Feb 2021, Stefan Seyfried wrote:
Hi all,
I just noticed that a build for SLES12 threw the following warning:
gcc -DHAVE_CONFIG_H -I. -I.. -DCONFDIR='"/etc"' -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g -c -o pdnsd-list.o `test -f 'list.c' || echo './'`list.c list.c: In function 'dlist_grow': list.c:113:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *((size_t *)&a->data[a->last])=a->lastsz; ^
While when build for SLES15, with similar CFLAGS="-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g" it does not warn.
The code is like:
109 size_t sz=0, allocsz=0, szincr, newsz; 110 if(a) { 111 sz=a->last+a->lastsz; 112 allocsz = (sz+DLISTCHUNKSIZEMASK)&(~DLISTCHUNKSIZEMASK); 113 *((size_t *)&a->data[a->last])=a->lastsz; 114 }
I was just starting to patch this, then I noticed that I could not even get the warning to show on newer distributions. (My OBS instance does not have factory available easily, so I just tested OBS build on SLES12 and SLES15, but the warning does not trigger on current Tumbleweed, too, even with "-Wstrict-aliasing" added to the CFLAGS mix.
What has changed?
The compiler, likely. To tell whether the *((size_t *)&... has an issue one would ned to see the aggregate type used for 'a'. In case a->data is not of type size_t * or size_t[] there is a possible strict-aliasing issue. The compiler change might be to no longer warn when a->data is for example an array of chars.
The rpmlint check said "this will break with future compilers" in SLES12. Is it now broken or have the compilers been fixed?
-- Richard Biener <rguenther@suse.de> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)