From ea2ec8d4f6487786d675a48baa982dc534beaa24 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Wed, 4 Dec 2019 09:57:47 +0200 Subject: [PATCH] GCC: remove -fno-delete-null-pointer-checks For GCC we're being cautious by passing the `-fno-delete-null-pointer-checks`. This option prevents some optimisation opportunities, so removing it can reduce code size. One particular optimisation loss occurs in `Callback` where a test similar to this occurs: extern void myfunc(); inline void foo(void (*fnptr)()) { if (fnptr) { do A; } else { do B; } }; foo(myfunc); With `-fno-delete-null-pointer-checks`, the compiler does not assume that `&myfunc` is non-null, and inserts the "null check" - seeing if the address is 0. But performing that test of the address is incorrect anyway - if myfunc actually could be at address 0, we'd still want to do A. Anyway, we do not have an equivalent option enabled for either Clang or IAR, and we have performed clean-ups avoiding issues with apparently-null vector tables in Clang already, for example #10534. Therefore it should(TM) be safe to remove the option for GCC. We do not have general data or code at address 0, only vectors are likely to be there, so it does not make sense to be globally restricting code generation for that. --- tools/profiles/debug.json | 2 +- tools/profiles/develop.json | 2 +- tools/profiles/release.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/profiles/debug.json b/tools/profiles/debug.json index b298ad7377..f175aecec2 100644 --- a/tools/profiles/debug.json +++ b/tools/profiles/debug.json @@ -4,7 +4,7 @@ "-Wno-unused-parameter", "-Wno-missing-field-initializers", "-fmessage-length=0", "-fno-exceptions", "-ffunction-sections", "-fdata-sections", "-funsigned-char", - "-MMD", "-fno-delete-null-pointer-checks", + "-MMD", "-fomit-frame-pointer", "-Og", "-g3", "-DMBED_DEBUG", "-DMBED_TRAP_ERRORS_ENABLED=1"], "asm": ["-x", "assembler-with-cpp"], diff --git a/tools/profiles/develop.json b/tools/profiles/develop.json index 7dd8a96d17..2cd3685bab 100644 --- a/tools/profiles/develop.json +++ b/tools/profiles/develop.json @@ -4,7 +4,7 @@ "-Wno-unused-parameter", "-Wno-missing-field-initializers", "-fmessage-length=0", "-fno-exceptions", "-ffunction-sections", "-fdata-sections", "-funsigned-char", - "-MMD", "-fno-delete-null-pointer-checks", + "-MMD", "-fomit-frame-pointer", "-Os", "-g", "-DMBED_TRAP_ERRORS_ENABLED=1"], "asm": ["-x", "assembler-with-cpp"], "c": ["-std=gnu11"], diff --git a/tools/profiles/release.json b/tools/profiles/release.json index 2aab24f6c8..075e8a46d2 100644 --- a/tools/profiles/release.json +++ b/tools/profiles/release.json @@ -4,7 +4,7 @@ "-Wno-unused-parameter", "-Wno-missing-field-initializers", "-fmessage-length=0", "-fno-exceptions", "-ffunction-sections", "-fdata-sections", "-funsigned-char", - "-MMD", "-fno-delete-null-pointer-checks", + "-MMD", "-fomit-frame-pointer", "-Os", "-DNDEBUG", "-g"], "asm": ["-x", "assembler-with-cpp"], "c": ["-std=gnu11"],