type-pun warnings in rpath_fixer.c
Closed this issue · 3 comments
getting a bunch of warnings about type-punning pointers , like these:
../src/platform/posix/rpath_fixer.c:106:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
elf->shoff = ((Elf32_Ehdr *)buf)->e_shoff;
^~~
../src/platform/posix/rpath_fixer.c:107:3: warning: dereferencing type-punned p>
elf->shentsize = ((Elf32_Ehdr *)buf)->e_shentsize;
^~~
it goes on until line 201. gcc used: 6.5.0
these should probably be fixed using memcpy, or by adding -fno-strict-aliasing to that TU.
gcc 13 / clang 17 gives no warnings. If you change the type of buf in that function to char
are there still warnings?
the type of buf is already char[]
. according to std, it's ok to dereference anything as char*
, but not vice versa: http://port70.net/~nsz/c/c11/n1570.html#6.5p7
btw, it might not even GCC version responsible for the warning but optimization level. i used [12/111] gcc -std=c99 -g -Og -Wpedantic -Wextra -Wall -Os -g0 -fdata-sections -ffunction-sections -gdwarf-3 -fno-unwind-tables -fno-asynchronous-unwind-tables -Wa,--noexecstack -fno-math-errno -mtune=generic -Wendif-labels -Winit-self -Wlogical-op -Wmissing-include-dirs -Wno-missing-braces -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Woverflow -Wstrict-aliasing=2 -Wstrict-prototypes -Wundef -Wvla -fstrict-aliasing -DMUON_BOOTSTRAPPED -I . -I .. -I ../include -I subprojects/tinyjson -I ../subprojects/tinyjson -I src/script -DMUON_PLATFORM_posix -MD -MQ muon.p/src/platform/posix/rpath_fixer.c.o -MF muon.p/src/platform/posix/rpath_fixer.c.o.d -o muon.p/src/platform/posix/rpath_fixer.c.o -c ../src/platform/posix/rpath_fixer.c
Your exact command line produces zero warnings for me with gcc 13.
This is not an optimization issue.