Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve reliability of the Callback implementation #755

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cores/arduino/mbed/platform/include/platform/Callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
#include <mstd_type_traits>
#include <mstd_functional>

#pragma GCC push_options
// This prevents the GCC compiler from applying optimizations that assume the code follows strict aliasing rules.
// In order to prevent bugs arising from undefined behavior that is tricky to find in the Callback implementation,
// or simply from compiler bugs in GCC.
#pragma GCC optimize("-fno-strict-aliasing")
// This prevents the GCC compiler from generating incorrect inline code for the Callback constructor.
#pragma GCC optimize("-fno-inline")

// Controlling switches from config:
// MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL - support storing non-trivial function objects
// MBED_CONF_PLATFORM_CALLBACK_COMPARABLE - support memcmp comparing stored objects (requires zero padding)
Expand All @@ -36,7 +44,6 @@
#define MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL 1
#endif


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

} // namespace mbed

#pragma GCC pop_options

#endif
Loading