1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Error even w/warnings disabled for no-return fcns (#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
This commit is contained in:
Earle F. Philhower, III 2022-03-03 15:10:57 -08:00 committed by GitHub
parent ead5f94dd3
commit 46190b61f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 8 deletions

View File

@ -21,11 +21,11 @@ runtime.tools.mkdir={runtime.platform.path}/tools/mkdir.py
runtime.tools.cp={runtime.platform.path}/tools/cp.py
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
compiler.warning_flags=-w -Werror=return-type
compiler.warning_flags.none=-w -Werror=return-type
compiler.warning_flags.default=-Werror=return-type
compiler.warning_flags.more=-Wall -Werror=return-type
compiler.warning_flags.all=-Wall -Wextra -Werror=return-type
compiler.warning_flags=@{runtime.platform.path}/tools/warnings/none
compiler.warning_flags.none=@{runtime.platform.path}/tools/warnings/none
compiler.warning_flags.default=@{runtime.platform.path}/tools/warnings/default
compiler.warning_flags.more=@{runtime.platform.path}/tools/warnings/more
compiler.warning_flags.all=@{runtime.platform.path}/tools/warnings/extra
build.lwip_lib=-llwip_gcc
build.lwip_include=lwip/include
@ -68,18 +68,18 @@ compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_S
compiler.libraries.ldflags=
compiler.c.cmd=xtensa-lx106-elf-gcc
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}
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}
compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls "-I{runtime.tools.xtensa-lx106-elf-gcc.path}/include/"
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
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
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
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
compiler.cpp.cmd=xtensa-lx106-elf-g++
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}
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}
compiler.as.cmd=xtensa-lx106-elf-as

12
tools/warnings/README.md Normal file
View File

@ -0,0 +1,12 @@
These are the warning options for the compiler at different levels.
Because G++ 10 produces code which crashes when a function is declared
to return a value but doesn't (this is undefined per the C++ specs, but legal
for C11 and above code as long as the [non]returned value is ignored), we
cannot warn them if we use "-w" to disable all warnings, and instead have
to delete every warning but "-Wreturn-type"
Generate the "none-g++" file with the following command:
````
./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++
````

View File

View File

1
tools/warnings/extra-g++ Normal file
View File

@ -0,0 +1 @@
-Wall -Wextra

1
tools/warnings/extra-gcc Normal file
View File

@ -0,0 +1 @@
-Wall -Wextra

1
tools/warnings/more-g++ Normal file
View File

@ -0,0 +1 @@
-Wall

1
tools/warnings/more-gcc Normal file
View File

@ -0,0 +1 @@
-Wall

52
tools/warnings/none-g++ Normal file
View File

@ -0,0 +1,52 @@
-Wno-address-of-packed-member
-Wno-aggressive-loop-optimizations
-Wno-analyzer-malloc-leak
-Wno-analyzer-null-argument
-Wno-analyzer-null-dereference
-Wno-analyzer-possible-null-argument
-Wno-analyzer-possible-null-dereference
-Wno-analyzer-stale-setjmp-buffer
-Wno-analyzer-tainted-array-index
-Wno-analyzer-unsafe-call-within-signal-handler
-Wno-attribute-warning
-Wno-attributes
-Wno-builtin-declaration-mismatch
-Wno-builtin-macro-redefined
-Wno-cannot-profile
-Wno-coverage-mismatch
-Wno-cpp
-Wno-deprecated
-Wno-deprecated-declarations
-Wno-div-by-zero
-Wno-endif-labels
-Wno-enum-compare
-Wno-hsa
-Wno-if-not-aligned
-Wno-ignored-attributes
-Wno-int-to-pointer-cast
-Wno-invalid-memory-model
-Wno-long-long
-Wno-lto-type-mismatch
-Wno-main
-Wno-missing-profile
-Wno-narrowing
-Wno-odr
-Wno-overflow
-Wno-packed-bitfield-compat
-Wno-pointer-compare
-Wno-pragmas
-Wno-prio-ctor-dtor
-Wno-psabi
-Wno-return-local-addr
-Wno-shift-count-negative
-Wno-shift-count-overflow
-Wno-shift-negative-value
-Wno-sizeof-array-argument
-Wno-switch-bool
-Wno-switch-outside-range
-Wno-switch-unreachable
-Wno-sync-nand
-Wno-trigraphs
-Wno-unused-result
-Wno-varargs
-Wno-vla

1
tools/warnings/none-gcc Normal file
View File

@ -0,0 +1 @@
-w