Skip to content

Commit 7bc601c

Browse files
committed
patches: add persistent callback fix
Importing #755 in the correct tree so it's preserved on rebuild
1 parent 1a7859c commit 7bc601c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From 28a199761f80a8400da5cac8fbcaf138d29ea596 Mon Sep 17 00:00:00 2001
2+
From: Martino Facchin <[email protected]>
3+
Date: Mon, 13 Nov 2023 09:40:06 +0100
4+
Subject: [PATCH 209/217] gcc: callback: prevent wrong optimizations
5+
6+
Porting of https://github.com/arduino/ArduinoCore-mbed/pull/755
7+
---
8+
platform/include/platform/Callback.h | 10 ++++++++++
9+
1 file changed, 10 insertions(+)
10+
11+
diff --git a/platform/include/platform/Callback.h b/platform/include/platform/Callback.h
12+
index e76a4f1979..3df0b9117f 100644
13+
--- a/platform/include/platform/Callback.h
14+
+++ b/platform/include/platform/Callback.h
15+
@@ -26,6 +26,14 @@
16+
#include <mstd_type_traits>
17+
#include <mstd_functional>
18+
19+
+#pragma GCC push_options
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+
+// This prevents the GCC compiler from generating incorrect inline code for the Callback constructor.
25+
+#pragma GCC optimize("-fno-inline")
26+
+
27+
// Controlling switches from config:
28+
// MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL - support storing non-trivial function objects
29+
// MBED_CONF_PLATFORM_CALLBACK_COMPARABLE - support memcmp comparing stored objects (requires zero padding)
30+
@@ -835,4 +843,6 @@ Callback(R(*func)(const volatile T *, ArgTs...), const volatile U *arg) -> Callb
31+
32+
} // namespace mbed
33+
34+
+#pragma GCC pop_options
35+
+
36+
#endif
37+
--
38+
2.42.0
39+

0 commit comments

Comments
 (0)