From 762e5251b480ddee63cc0fbf2310e510f5eebe77 Mon Sep 17 00:00:00 2001
From: Dylan Laduranty <dylan.laduranty@mesotic.com>
Date: Mon, 21 Jan 2019 17:10:19 +0100
Subject: [PATCH] tests/unittests: disable optimization for
 test_atomic_inc_rollover

Disable optimization for this function only with CPU_SAML1X MCUs due to an internal crosscompiler bug
---
 tests/unittests/tests-core/tests-core-atomic.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/unittests/tests-core/tests-core-atomic.c b/tests/unittests/tests-core/tests-core-atomic.c
index 7089f9edfa..f05bab05b6 100644
--- a/tests/unittests/tests-core/tests-core-atomic.c
+++ b/tests/unittests/tests-core/tests-core-atomic.c
@@ -51,7 +51,11 @@ static void test_atomic_inc_negative(void)
         TEST_ASSERT_EQUAL_INT(i + 1, atomic_load(&res));
     }
 }
-
+/* Prevent compiler optimization for SAML1X because of gcc internal bug */
+#ifdef CPU_SAML1X
+#pragma GCC push_options
+#pragma GCC optimize ("O0")
+#endif
 static void test_atomic_inc_rollover(void)
 {
     atomic_int res = ATOMIC_VAR_INIT(INT_MAX - 30);
@@ -67,7 +71,9 @@ static void test_atomic_inc_rollover(void)
     TEST_ASSERT_EQUAL_INT(INT_MIN + 1, atomic_fetch_add(&res, 1));
     TEST_ASSERT_EQUAL_INT(INT_MIN + 2, atomic_load(&res));
 }
-
+#ifdef CPU_SAML1X
+#pragma GCC pop_options
+#endif
 /* Test atomic_fetch_sub */
 static void test_atomic_dec_negative(void)
 {
-- 
GitLab