Skip to content

Commit 584975a

Browse files
authored
Fix incorrect inline code generation
This prevents the GCC compiler from generating incorrect inline code for the Callback constructor.
1 parent 21be574 commit 584975a

File tree

1 file changed

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

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
#ifndef MBED_CALLBACK_H
1818
#define MBED_CALLBACK_H
1919

20-
// This prevents the GCC compiler from applying optimizations that assume the code follows strict aliasing rules.
21-
// In order to prevent bugs arising from undefined behavior that is tricky to find in the Callback implementation,
22-
// or simply from compiler bugs in GCC.
23-
#pragma GCC optimize("-fno-strict-aliasing")
24-
2520
#include <cstring>
2621
#include <mstd_cstddef>
2722
#include <stdint.h>
@@ -31,6 +26,14 @@
3126
#include <mstd_type_traits>
3227
#include <mstd_functional>
3328

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+
3437
// Controlling switches from config:
3538
// MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL - support storing non-trivial function objects
3639
// MBED_CONF_PLATFORM_CALLBACK_COMPARABLE - support memcmp comparing stored objects (requires zero padding)
@@ -41,7 +44,6 @@
4144
#define MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL 1
4245
#endif
4346

44-
4547
namespace mbed {
4648
/** \addtogroup platform-public-api */
4749
/** @{*/
@@ -840,4 +842,6 @@ Callback(R(*func)(const volatile T *, ArgTs...), const volatile U *arg) -> Callb
840842

841843
} // namespace mbed
842844

845+
#pragma GCC pop_options
846+
843847
#endif

0 commit comments

Comments
 (0)