[rtems commit] score: Add and use RTEMS_UNREACHABLE

Sebastian Huber sebh at rtems.org
Wed Mar 23 06:54:26 UTC 2016


Module:    rtems
Branch:    master
Commit:    e8d9b26f43b87c0a128109e0c0e1ac3d0e3a1278
Changeset: http://git.rtems.org/rtems/commit/?id=e8d9b26f43b87c0a128109e0c0e1ac3d0e3a1278

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Mar 22 07:24:14 2016 +0100

score: Add and use RTEMS_UNREACHABLE

---

 cpukit/score/include/rtems/score/assert.h   |  9 ---------
 cpukit/score/include/rtems/score/basedefs.h | 19 +++++++++++++++++++
 cpukit/score/src/threadglobalconstruction.c |  3 +--
 cpukit/score/src/threadrestart.c            |  6 ++----
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/cpukit/score/include/rtems/score/assert.h b/cpukit/score/include/rtems/score/assert.h
index d4253f8..69736ae 100644
--- a/cpukit/score/include/rtems/score/assert.h
+++ b/cpukit/score/include/rtems/score/assert.h
@@ -120,15 +120,6 @@ extern "C" {
   bool _Debug_Is_owner_of_allocator( void );
 #endif
 
-/**
- * @brief Asserts that this point is not reached during run-time.
- */
-#if RTEMS_SCHEDSIM
-#define _Assert_Not_reached()
-#else
-#define _Assert_Not_reached() _Assert( 0 )
-#endif
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/cpukit/score/include/rtems/score/basedefs.h b/cpukit/score/include/rtems/score/basedefs.h
index facaed9..24a56f2 100644
--- a/cpukit/score/include/rtems/score/basedefs.h
+++ b/cpukit/score/include/rtems/score/basedefs.h
@@ -191,6 +191,25 @@
 /* Provided for backward compatibility */
 #define RTEMS_COMPILER_PACKED_ATTRIBUTE RTEMS_PACKED
 
+#if defined(RTEMS_DEBUG) && !defined(RTEMS_SCHEDSIM)
+  #define _Assert_Unreachable() _Assert( 0 )
+#else
+  #define _Assert_Unreachable() do { } while ( 0 )
+#endif
+
+/**
+ * @brief Tells the compiler that this program point is unreachable.
+ */
+#if defined(__GNUC__) && !defined(RTEMS_SCHEDSIM)
+  #define RTEMS_UNREACHABLE() \
+    do { \
+      __builtin_unreachable(); \
+      _Assert_Unreachable(); \
+    } while ( 0 )
+#else
+  #define RTEMS_UNREACHABLE() _Assert_Unreachable()
+#endif
+
 #if __cplusplus >= 201103L
   #define RTEMS_STATIC_ASSERT(cond, msg) \
     static_assert(cond, # msg)
diff --git a/cpukit/score/src/threadglobalconstruction.c b/cpukit/score/src/threadglobalconstruction.c
index 1e84124..997f285 100644
--- a/cpukit/score/src/threadglobalconstruction.c
+++ b/cpukit/score/src/threadglobalconstruction.c
@@ -61,6 +61,5 @@ void _Thread_Global_construction(
   _Thread_Disable_dispatch();
   _Thread_Restart( executing, executing, entry );
   _Thread_Enable_dispatch();
-
-  _Assert_Not_reached();
+  RTEMS_UNREACHABLE();
 }
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 155acaa..59754a8 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -237,8 +237,7 @@ void _Thread_Life_action_handler(
     }
 
     _Thread_Enable_dispatch();
-
-    _Assert_Not_reached();
+    RTEMS_UNREACHABLE();
   } else {
     _Assert( _Thread_Is_life_restarting( previous_life_state ) );
 
@@ -258,8 +257,7 @@ void _Thread_Life_action_handler(
 
       _Thread_Load_environment( executing );
       _Thread_Restart_self( executing );
-
-      _Assert_Not_reached();
+      RTEMS_UNREACHABLE();
     }
   }
 }



More information about the vc mailing list