Skip to content

Commit 21be574

Browse files
authored
Prevent aliasing bugs in the Callback code
This change 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. The reason for making the change now is concrete customer cases where incorrect machine code was generated in relation to Mbed Callbacks.
1 parent fee275d commit 21be574

File tree

1 file changed

+5
-0
lines changed
  • cores/arduino/mbed/platform/include/platform

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
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+
2025
#include <cstring>
2126
#include <mstd_cstddef>
2227
#include <stdint.h>

0 commit comments

Comments
 (0)