Skip to content

Commit 46190b6

Browse files
Error even w/warnings disabled for no-return fcns (esp8266#8495)
* Error even w/warnings disabled for no-return fcns A function whose prototype says it will return a value but doesn't is undefined behaviour in C++. GCC 10 will generate code that crashes in this case. In warnings==None mode, insterad of turning off all warnings with `-w`, explicitly list all G++ possible warnings except for the `no-return` warning which catches this programming error. * Use different lists for GCC vs G++ G++ and GCC have different warning options, so use different lists. * Make separate file for each level, add readme The readme now includes the exact commands required to regenerate the none-XXX files, no manual editing needed. * Address review comments, only adjusts G++/None
1 parent ead5f94 commit 46190b6

10 files changed

+77
-8
lines changed

platform.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ runtime.tools.mkdir={runtime.platform.path}/tools/mkdir.py
2121
runtime.tools.cp={runtime.platform.path}/tools/cp.py
2222
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
2323

24-
compiler.warning_flags=-w -Werror=return-type
25-
compiler.warning_flags.none=-w -Werror=return-type
26-
compiler.warning_flags.default=-Werror=return-type
27-
compiler.warning_flags.more=-Wall -Werror=return-type
28-
compiler.warning_flags.all=-Wall -Wextra -Werror=return-type
24+
compiler.warning_flags=@{runtime.platform.path}/tools/warnings/none
25+
compiler.warning_flags.none=@{runtime.platform.path}/tools/warnings/none
26+
compiler.warning_flags.default=@{runtime.platform.path}/tools/warnings/default
27+
compiler.warning_flags.more=@{runtime.platform.path}/tools/warnings/more
28+
compiler.warning_flags.all=@{runtime.platform.path}/tools/warnings/extra
2929

3030
build.lwip_lib=-llwip_gcc
3131
build.lwip_include=lwip/include
@@ -68,18 +68,18 @@ compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_S
6868
compiler.libraries.ldflags=
6969

7070
compiler.c.cmd=xtensa-lx106-elf-gcc
71-
compiler.c.flags=-c {compiler.warning_flags} -std=gnu17 {build.stacksmash_flags} -Os -g -free -fipa-pta -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
71+
compiler.c.flags=-c {compiler.warning_flags}-gcc -std=gnu17 {build.stacksmash_flags} -Os -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
7272

7373
compiler.S.cmd=xtensa-lx106-elf-gcc
7474
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls "-I{runtime.tools.xtensa-lx106-elf-gcc.path}/include/"
7575

76-
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{build.path}" "-L{compiler.libc.path}/lib" "-Tlocal.eagle.flash.ld" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
76+
compiler.c.elf.flags=-g {compiler.warning_flags}-gcc -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{build.path}" "-L{compiler.libc.path}/lib" "-Tlocal.eagle.flash.ld" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
7777

7878
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
7979
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
8080

8181
compiler.cpp.cmd=xtensa-lx106-elf-g++
82-
compiler.cpp.flags=-c {compiler.warning_flags} {build.stacksmash_flags} -Os -g -free -fipa-pta -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
82+
compiler.cpp.flags=-c {compiler.warning_flags}-g++ {build.stacksmash_flags} -Os -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
8383

8484
compiler.as.cmd=xtensa-lx106-elf-as
8585

tools/warnings/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
These are the warning options for the compiler at different levels.
2+
3+
Because G++ 10 produces code which crashes when a function is declared
4+
to return a value but doesn't (this is undefined per the C++ specs, but legal
5+
for C11 and above code as long as the [non]returned value is ignored), we
6+
cannot warn them if we use "-w" to disable all warnings, and instead have
7+
to delete every warning but "-Wreturn-type"
8+
9+
Generate the "none-g++" file with the following command:
10+
````
11+
./tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc --help=warnings -Q | grep '\[enabled\]' | grep -v 'return-type' | awk '{print $1}' | sed 's/-W/-Wno-/' | grep -v = | grep -v -- -f | egrep -v '(c11-c2x-compat|c90-c99-compat|c99-c11-compat|declaration-after-statement|designated-init|discarded-array-qualifiers|discarded-qualifiers|implicit-int|incompatible-pointer-types|int-conversion|old-style-definition|override-init-side-effects|pointer-to-int-cast)' > tools/warnings/none-g++
12+
````

tools/warnings/default-g++

Whitespace-only changes.

tools/warnings/default-gcc

Whitespace-only changes.

tools/warnings/extra-g++

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Wall -Wextra

tools/warnings/extra-gcc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Wall -Wextra

tools/warnings/more-g++

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Wall

tools/warnings/more-gcc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Wall

tools/warnings/none-g++

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-Wno-address-of-packed-member
2+
-Wno-aggressive-loop-optimizations
3+
-Wno-analyzer-malloc-leak
4+
-Wno-analyzer-null-argument
5+
-Wno-analyzer-null-dereference
6+
-Wno-analyzer-possible-null-argument
7+
-Wno-analyzer-possible-null-dereference
8+
-Wno-analyzer-stale-setjmp-buffer
9+
-Wno-analyzer-tainted-array-index
10+
-Wno-analyzer-unsafe-call-within-signal-handler
11+
-Wno-attribute-warning
12+
-Wno-attributes
13+
-Wno-builtin-declaration-mismatch
14+
-Wno-builtin-macro-redefined
15+
-Wno-cannot-profile
16+
-Wno-coverage-mismatch
17+
-Wno-cpp
18+
-Wno-deprecated
19+
-Wno-deprecated-declarations
20+
-Wno-div-by-zero
21+
-Wno-endif-labels
22+
-Wno-enum-compare
23+
-Wno-hsa
24+
-Wno-if-not-aligned
25+
-Wno-ignored-attributes
26+
-Wno-int-to-pointer-cast
27+
-Wno-invalid-memory-model
28+
-Wno-long-long
29+
-Wno-lto-type-mismatch
30+
-Wno-main
31+
-Wno-missing-profile
32+
-Wno-narrowing
33+
-Wno-odr
34+
-Wno-overflow
35+
-Wno-packed-bitfield-compat
36+
-Wno-pointer-compare
37+
-Wno-pragmas
38+
-Wno-prio-ctor-dtor
39+
-Wno-psabi
40+
-Wno-return-local-addr
41+
-Wno-shift-count-negative
42+
-Wno-shift-count-overflow
43+
-Wno-shift-negative-value
44+
-Wno-sizeof-array-argument
45+
-Wno-switch-bool
46+
-Wno-switch-outside-range
47+
-Wno-switch-unreachable
48+
-Wno-sync-nand
49+
-Wno-trigraphs
50+
-Wno-unused-result
51+
-Wno-varargs
52+
-Wno-vla

tools/warnings/none-gcc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-w

0 commit comments

Comments
 (0)