From 8372958f4673857cf3ced3b25f91e5a6e258f33c Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sat, 4 May 2019 18:22:18 +0100 Subject: [PATCH 1/2] address gcc9 warnings --- src/main/blackbox/blackbox.c | 11 +++++++++++ src/main/telemetry/mavlink.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index d70fb399d2..db7f0e7fdc 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1045,6 +1045,13 @@ static void writeInterframe(void) blackboxLoggedAnyFrames = true; } +// for gcc9 (and maybe later), we warn on (mainly harmless) unaligned packed structure member pointer access +// minimise the effect to the affected functions and compiler versions. +#if (__GNUC__ >= 9) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" +#endif + /* Write the contents of the global "slowHistory" to the log as an "S" frame. Because this data is logged so * infrequently, delta updates are not reasonable, so we log independent frames. */ static void writeSlowFrame(void) @@ -1131,6 +1138,10 @@ static void loadSlowState(blackboxSlowState_t *slow) } +#if (__GNUC__ >= 9) +#pragma GCC diagnostic pop +#endif + /** * If the data in the slow frame has changed, log a slow frame. * diff --git a/src/main/telemetry/mavlink.c b/src/main/telemetry/mavlink.c index 660e6f74c5..e9fd6931ad 100755 --- a/src/main/telemetry/mavlink.c +++ b/src/main/telemetry/mavlink.c @@ -75,6 +75,10 @@ // until this is resolved in mavlink library - ignore -Wpedantic for mavlink code #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" +// For gcc9, the mavlink libary also fails on unaligned unaligned packed structure member pointer access +#if (__GNUC__ >= 9) +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" +#endif #include "common/mavlink.h" #pragma GCC diagnostic pop From 478228e04bc4d870e242c7316932b97282ac0eaa Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sat, 4 May 2019 20:32:10 +0100 Subject: [PATCH 2/2] revert individual file GCC9 warning exceptions and instead add a global exception to platform.h --- src/main/blackbox/blackbox.c | 11 ----------- src/main/platform.h | 7 +++++++ src/main/telemetry/mavlink.c | 4 ---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index db7f0e7fdc..d70fb399d2 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1045,13 +1045,6 @@ static void writeInterframe(void) blackboxLoggedAnyFrames = true; } -// for gcc9 (and maybe later), we warn on (mainly harmless) unaligned packed structure member pointer access -// minimise the effect to the affected functions and compiler versions. -#if (__GNUC__ >= 9) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif - /* Write the contents of the global "slowHistory" to the log as an "S" frame. Because this data is logged so * infrequently, delta updates are not reasonable, so we log independent frames. */ static void writeSlowFrame(void) @@ -1138,10 +1131,6 @@ static void loadSlowState(blackboxSlowState_t *slow) } -#if (__GNUC__ >= 9) -#pragma GCC diagnostic pop -#endif - /** * If the data in the slow frame has changed, log a slow frame. * diff --git a/src/main/platform.h b/src/main/platform.h index 67365d6ba6..657b067480 100644 --- a/src/main/platform.h +++ b/src/main/platform.h @@ -62,3 +62,10 @@ #include "target/common.h" #include "target.h" #include "target/common_post.h" + +// Remove the unaligned packed structure member pointer access warning +// The compiler guarantees that unaligned access is safe for packed structures. + +#if (__GNUC__ >= 9) +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" +#endif diff --git a/src/main/telemetry/mavlink.c b/src/main/telemetry/mavlink.c index e9fd6931ad..660e6f74c5 100755 --- a/src/main/telemetry/mavlink.c +++ b/src/main/telemetry/mavlink.c @@ -75,10 +75,6 @@ // until this is resolved in mavlink library - ignore -Wpedantic for mavlink code #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" -// For gcc9, the mavlink libary also fails on unaligned unaligned packed structure member pointer access -#if (__GNUC__ >= 9) -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif #include "common/mavlink.h" #pragma GCC diagnostic pop