Skip to content

Commit

Permalink
Error even w/warnings disabled for no-return fcns (#8495)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
earlephilhower committed Mar 3, 2022
1 parent ead5f94 commit 46190b6
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 8 deletions.
16 changes: 8 additions & 8 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@jjsuwa-sys3175

jjsuwa-sys3175 Mar 27, 2022

Contributor

runtime.platform.path can contain space, such as "C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266".

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=esp8266com:esp8266:generic:xtal=160,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,ResetMethod=nodemcu,CrystalFreq=26,FlashFreq=80,FlashMode=qio,eesz=4M2M,led=2,sdk=nonosdk_191122,ip=lm2n,dbg=Disabled,lvl=NoAssert-NDEBUG,wipe=none,baud=921600 -ide-version=10815 -build-path C:\Users\Administrator\AppData\Local\Temp\arduino_build_369083 -warnings=all -build-cache C:\Users\Administrator\AppData\Local\Temp\arduino_cache_913876 -prefs=build.warn_data_percentage=75 -verbose C:\Users\Administrator\Documents\Arduino\WiFiMC\WiFiMC.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=esp8266com:esp8266:generic:xtal=160,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,ResetMethod=nodemcu,CrystalFreq=26,FlashFreq=80,FlashMode=qio,eesz=4M2M,led=2,sdk=nonosdk_191122,ip=lm2n,dbg=Disabled,lvl=NoAssert-NDEBUG,wipe=none,baud=921600 -ide-version=10815 -build-path C:\Users\Administrator\AppData\Local\Temp\arduino_build_369083 -warnings=all -build-cache C:\Users\Administrator\AppData\Local\Temp\arduino_cache_913876 -prefs=build.warn_data_percentage=75 -verbose C:\Users\Administrator\Documents\Arduino\WiFiMC\WiFiMC.ino
Using board 'generic' from platform in folder: C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266
Using core 'esp8266' from platform in folder: C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266
"C:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/python3/python3" -I "C:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/makecorever.py" --build_path "C:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083" --platform_path "C:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266" --version 3.1.0-dev
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/include" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/lwip2/include" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083/core" -c "@C:\\Program" Files "(x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/warnings/none-g++" -Os -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++17 -ffunction-sections -fdata-sections -fno-exceptions -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -w -x c++ -E -CC -DNONOSDK22x_191122=1 -DF_CPU=160000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=0 -DLWIP_IPV6=0 -DNDEBUG -DARDUINO=10815 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_GENERIC\"" -DLED_BUILTIN=2 -DFLASHMODE_QIO "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266\\cores\\esp8266" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266\\variants\\generic" "C:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083\\sketch\\WiFiMC.ino.cpp" -o nul
Error while detecting libraries included by C:\Users\Administrator\AppData\Local\Temp\arduino_build_369083\sketch\WiFiMC.ino.cpp
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/include" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/lwip2/include" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083/core" -c "@C:\\Program" Files "(x86)\\Arduino\\hardware\\esp8266com\\esp8266/tools/warnings/none-g++" -Os -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++17 -ffunction-sections -fdata-sections -fno-exceptions -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -w -x c++ -E -CC -DNONOSDK22x_191122=1 -DF_CPU=160000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=0 -DLWIP_IPV6=0 -DNDEBUG -DARDUINO=10815 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_GENERIC\"" -DLED_BUILTIN=2 -DFLASHMODE_QIO "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266\\cores\\esp8266" "-IC:\\Program Files (x86)\\Arduino\\hardware\\esp8266com\\esp8266\\variants\\generic" "C:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083\\sketch\\WiFiMC.ino.cpp" -o "C:\\Users\\Administrator\\AppData\\Local\\Temp\\arduino_build_369083\\preproc\\ctags_target_for_gcc_minus_e.cpp"
xtensa-lx106-elf-g++: error: C:\Program: No such file or directory
xtensa-lx106-elf-g++: error: Files: No such file or directory
xtensa-lx106-elf-g++: error: (x86)\Arduino\hardware\esp8266com\esp8266/tools/warnings/none-g++: No such file or directory
exit status 1

This comment has been minimized.

Copy link
@earlephilhower

earlephilhower Mar 29, 2022

Author Collaborator

Good catch!

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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions tools/warnings/README.md
Original file line number Diff line number Diff line change
@@ -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++
````
Empty file added tools/warnings/default-g++
Empty file.
Empty file added tools/warnings/default-gcc
Empty file.
1 change: 1 addition & 0 deletions tools/warnings/extra-g++
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall -Wextra
1 change: 1 addition & 0 deletions tools/warnings/extra-gcc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall -Wextra
1 change: 1 addition & 0 deletions tools/warnings/more-g++
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall
1 change: 1 addition & 0 deletions tools/warnings/more-gcc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall
52 changes: 52 additions & 0 deletions tools/warnings/none-g++
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tools/warnings/none-gcc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-w

0 comments on commit 46190b6

Please sign in to comment.