Skip to content

Commit 1a7859c

Browse files
authored
Merge pull request #755 from alrvid/main
Improve reliability of the Callback implementation
2 parents fee275d + 584975a commit 1a7859c

File tree

1 file changed

+10
-1
lines changed
  • cores/arduino/mbed/platform/include/platform

1 file changed

+10
-1
lines changed

cores/arduino/mbed/platform/include/platform/Callback.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
#include <mstd_type_traits>
2727
#include <mstd_functional>
2828

29+
#pragma GCC push_options
30+
// This prevents the GCC compiler from applying optimizations that assume the code follows strict aliasing rules.
31+
// In order to prevent bugs arising from undefined behavior that is tricky to find in the Callback implementation,
32+
// or simply from compiler bugs in GCC.
33+
#pragma GCC optimize("-fno-strict-aliasing")
34+
// This prevents the GCC compiler from generating incorrect inline code for the Callback constructor.
35+
#pragma GCC optimize("-fno-inline")
36+
2937
// Controlling switches from config:
3038
// MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL - support storing non-trivial function objects
3139
// MBED_CONF_PLATFORM_CALLBACK_COMPARABLE - support memcmp comparing stored objects (requires zero padding)
@@ -36,7 +44,6 @@
3644
#define MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL 1
3745
#endif
3846

39-
4047
namespace mbed {
4148
/** \addtogroup platform-public-api */
4249
/** @{*/
@@ -835,4 +842,6 @@ Callback(R(*func)(const volatile T *, ArgTs...), const volatile U *arg) -> Callb
835842

836843
} // namespace mbed
837844

845+
#pragma GCC pop_options
846+
838847
#endif

0 commit comments

Comments
 (0)