[rtems commit] score: Fix C/C++ compatibility issue

Sebastian Huber sebh at rtems.org
Fri Sep 23 05:05:33 UTC 2016


Module:    rtems
Branch:    4.11
Commit:    75a6584a43a9ab4170376d31fe4041bbaaa7f547
Changeset: http://git.rtems.org/rtems/commit/?id=75a6584a43a9ab4170376d31fe4041bbaaa7f547

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Sep 23 06:52:33 2016 +0200

score: Fix C/C++ compatibility issue

Only use CPU_Per_CPU_control if it contains at least one filed.  In GNU
C empty structures have a size of zero.  In C++ structures have a
non-zero size.  In case CPU_PER_CPU_CONTROL_SIZE is defined to zero,
then this structure is not used anymore.

Close #2789.

---

 cpukit/score/cpu/arm/rtems/score/cpu.h      |  4 ----
 cpukit/score/cpu/bfin/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/epiphany/rtems/score/cpu.h |  3 ---
 cpukit/score/cpu/i386/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/lm32/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/m32c/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/m68k/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/mips/rtems/score/cpu.h     |  4 ----
 cpukit/score/cpu/moxie/rtems/score/cpu.h    |  4 ----
 cpukit/score/cpu/nios2/rtems/score/cpu.h    |  4 ----
 cpukit/score/cpu/no_cpu/rtems/score/cpu.h   |  6 +++++-
 cpukit/score/cpu/or1k/rtems/score/cpu.h     |  3 ---
 cpukit/score/cpu/powerpc/rtems/score/cpu.h  |  4 ----
 cpukit/score/cpu/sh/rtems/score/cpu.h       |  4 ----
 cpukit/score/cpu/sparc64/rtems/score/cpu.h  |  4 ----
 cpukit/score/cpu/v850/rtems/score/cpu.h     |  4 ----
 cpukit/score/include/rtems/score/percpu.h   | 10 ++++++----
 cpukit/score/src/percpuasm.c                | 10 ++++++----
 18 files changed, 17 insertions(+), 67 deletions(-)

diff --git a/cpukit/score/cpu/arm/rtems/score/cpu.h b/cpukit/score/cpu/arm/rtems/score/cpu.h
index 6ed6ef9..6404518 100644
--- a/cpukit/score/cpu/arm/rtems/score/cpu.h
+++ b/cpukit/score/cpu/arm/rtems/score/cpu.h
@@ -242,10 +242,6 @@ extern "C" {
 /**@{**/
 
 typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
-typedef struct {
 #if defined(ARM_MULTILIB_ARCH_V4)
   uint32_t register_cpsr;
   uint32_t register_r4;
diff --git a/cpukit/score/cpu/bfin/rtems/score/cpu.h b/cpukit/score/cpu/bfin/rtems/score/cpu.h
index 52fb3f8..84dddb8 100644
--- a/cpukit/score/cpu/bfin/rtems/score/cpu.h
+++ b/cpukit/score/cpu/bfin/rtems/score/cpu.h
@@ -388,10 +388,6 @@ extern "C" {
 
 #ifndef ASM
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /**
  * @defgroup CPUContext Processor Dependent Context Management
  *
diff --git a/cpukit/score/cpu/epiphany/rtems/score/cpu.h b/cpukit/score/cpu/epiphany/rtems/score/cpu.h
index fb5e6b2..aa89d2d 100644
--- a/cpukit/score/cpu/epiphany/rtems/score/cpu.h
+++ b/cpukit/score/cpu/epiphany/rtems/score/cpu.h
@@ -838,9 +838,6 @@ void _CPU_Context_Initialize(
 #define CPU_TIMESTAMP_USE_INT64 TRUE
 #define CPU_TIMESTAMP_USE_INT64_INLINE FALSE
 
-typedef struct {
-/* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
 #endif /* ASM */
 
 /**
diff --git a/cpukit/score/cpu/i386/rtems/score/cpu.h b/cpukit/score/cpu/i386/rtems/score/cpu.h
index 96cea5a..6c3b441 100644
--- a/cpukit/score/cpu/i386/rtems/score/cpu.h
+++ b/cpukit/score/cpu/i386/rtems/score/cpu.h
@@ -142,10 +142,6 @@ extern "C" {
 
 #ifndef ASM
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /*
  *  Basic integer context for the i386 family.
  */
diff --git a/cpukit/score/cpu/lm32/rtems/score/cpu.h b/cpukit/score/cpu/lm32/rtems/score/cpu.h
index 4cd07ba..32dedbe 100644
--- a/cpukit/score/cpu/lm32/rtems/score/cpu.h
+++ b/cpukit/score/cpu/lm32/rtems/score/cpu.h
@@ -380,10 +380,6 @@ extern "C" {
 
 /* may need to put some structures here.  */
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /**
  * @defgroup CPUContext Processor Dependent Context Management
  *
diff --git a/cpukit/score/cpu/m32c/rtems/score/cpu.h b/cpukit/score/cpu/m32c/rtems/score/cpu.h
index 6ca7972..bd5fdfe 100644
--- a/cpukit/score/cpu/m32c/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m32c/rtems/score/cpu.h
@@ -403,10 +403,6 @@ extern "C" {
 
 /* may need to put some structures here.  */
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /**
  * @defgroup CPUContext Processor Dependent Context Management
  *
diff --git a/cpukit/score/cpu/m68k/rtems/score/cpu.h b/cpukit/score/cpu/m68k/rtems/score/cpu.h
index 913bb78..4f81463 100644
--- a/cpukit/score/cpu/m68k/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m68k/rtems/score/cpu.h
@@ -125,10 +125,6 @@ extern "C" {
 
 /* structures */
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /*
  *  Basic integer context for the m68k family.
  */
diff --git a/cpukit/score/cpu/mips/rtems/score/cpu.h b/cpukit/score/cpu/mips/rtems/score/cpu.h
index 4e426f8..1211e3c 100644
--- a/cpukit/score/cpu/mips/rtems/score/cpu.h
+++ b/cpukit/score/cpu/mips/rtems/score/cpu.h
@@ -383,10 +383,6 @@ extern "C" {
 
 #ifndef ASM
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /* WARNING: If this structure is modified, the constants in cpu.h must be updated. */
 #if (__mips == 1) || (__mips == 32)
 #define __MIPS_REGISTER_TYPE     uint32_t
diff --git a/cpukit/score/cpu/moxie/rtems/score/cpu.h b/cpukit/score/cpu/moxie/rtems/score/cpu.h
index 3422d02..7e549ae 100644
--- a/cpukit/score/cpu/moxie/rtems/score/cpu.h
+++ b/cpukit/score/cpu/moxie/rtems/score/cpu.h
@@ -319,10 +319,6 @@ extern "C" {
 
 /* may need to put some structures here.  */
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /*
  * Contexts
  *
diff --git a/cpukit/score/cpu/nios2/rtems/score/cpu.h b/cpukit/score/cpu/nios2/rtems/score/cpu.h
index d9a7bbd..6b6f1cd 100644
--- a/cpukit/score/cpu/nios2/rtems/score/cpu.h
+++ b/cpukit/score/cpu/nios2/rtems/score/cpu.h
@@ -111,10 +111,6 @@ extern "C" {
 
 #ifndef ASM
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /**
  * @brief Thread register context.
  *
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
index f556087..2f507bf 100644
--- a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
@@ -478,7 +478,11 @@ extern "C" {
  * @brief The CPU specific per-CPU control.
  *
  * The CPU port can place here all state information that must be available and
- * maintained for each CPU in the system.
+ * maintained for each processor in the system.  This structure must contain at
+ * least one field for C/C++ compatibility.  In GNU C empty structures have a
+ * size of zero.  In C++ structures have a non-zero size.  In case
+ * CPU_PER_CPU_CONTROL_SIZE is defined to zero, then this structure is not
+ * used.
  */
 typedef struct {
   /* CPU specific per-CPU state */
diff --git a/cpukit/score/cpu/or1k/rtems/score/cpu.h b/cpukit/score/cpu/or1k/rtems/score/cpu.h
index 21cbb6d..fb809f7 100644
--- a/cpukit/score/cpu/or1k/rtems/score/cpu.h
+++ b/cpukit/score/cpu/or1k/rtems/score/cpu.h
@@ -818,9 +818,6 @@ void _CPU_Context_Initialize(
 #define CPU_TIMESTAMP_USE_INT64 TRUE
 #define CPU_TIMESTAMP_USE_INT64_INLINE FALSE
 
-typedef struct {
-/* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
 #endif /* ASM */
 
 #define CPU_SIZEOF_POINTER 4
diff --git a/cpukit/score/cpu/powerpc/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
index 7fef878..9cc4105 100644
--- a/cpukit/score/cpu/powerpc/rtems/score/cpu.h
+++ b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
@@ -247,10 +247,6 @@ extern "C" {
 
 #ifndef ASM
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /*
  * Non-volatile context according to E500ABIUG, EABI and 32-bit TLS (according
  * to "Power Architecture 32-bit Application Binary Interface Supplement 1.0 -
diff --git a/cpukit/score/cpu/sh/rtems/score/cpu.h b/cpukit/score/cpu/sh/rtems/score/cpu.h
index 76220f7..84f5fbc 100644
--- a/cpukit/score/cpu/sh/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sh/rtems/score/cpu.h
@@ -285,10 +285,6 @@ extern "C" {
 
 /* may need to put some structures here.  */
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /*
  * Contexts
  *
diff --git a/cpukit/score/cpu/sparc64/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
index 37e8325..73c7124 100644
--- a/cpukit/score/cpu/sparc64/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
@@ -218,10 +218,6 @@ extern "C" {
 #ifndef ASM
 
 typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
-typedef struct {
   uint64_t    l0;
   uint64_t    l1;
   uint64_t    l2;
diff --git a/cpukit/score/cpu/v850/rtems/score/cpu.h b/cpukit/score/cpu/v850/rtems/score/cpu.h
index 9725900..0cda4e5 100644
--- a/cpukit/score/cpu/v850/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/rtems/score/cpu.h
@@ -373,10 +373,6 @@ extern "C" {
 
 #define CPU_PER_CPU_CONTROL_SIZE 0
 
-typedef struct {
-  /* There is no CPU specific per-CPU state */
-} CPU_Per_CPU_control;
-
 /**
  * @defgroup CPUContext Processor Dependent Context Management
  *
diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
index 9ce68ef..5ab2567 100644
--- a/cpukit/score/include/rtems/score/percpu.h
+++ b/cpukit/score/include/rtems/score/percpu.h
@@ -231,10 +231,12 @@ typedef struct {
  *  This structure is used to hold per core state information.
  */
 typedef struct Per_CPU_Control {
-  /**
-   * @brief CPU port specific control.
-   */
-  CPU_Per_CPU_control cpu_per_cpu;
+  #if CPU_PER_CPU_CONTROL_SIZE > 0
+    /**
+     * @brief CPU port specific control.
+     */
+    CPU_Per_CPU_control cpu_per_cpu;
+  #endif
 
   #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \
       (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
diff --git a/cpukit/score/src/percpuasm.c b/cpukit/score/src/percpuasm.c
index 15b49c7..53e6326 100644
--- a/cpukit/score/src/percpuasm.c
+++ b/cpukit/score/src/percpuasm.c
@@ -64,10 +64,12 @@ RTEMS_STATIC_ASSERT(
   );
 #endif
 
-RTEMS_STATIC_ASSERT(
-  sizeof( CPU_Per_CPU_control ) == CPU_PER_CPU_CONTROL_SIZE,
-  CPU_PER_CPU_CONTROL_SIZE
-);
+#if CPU_PER_CPU_CONTROL_SIZE > 0
+  RTEMS_STATIC_ASSERT(
+    sizeof( CPU_Per_CPU_control ) == CPU_PER_CPU_CONTROL_SIZE,
+    CPU_PER_CPU_CONTROL_SIZE
+  );
+#endif
 
 #if defined( RTEMS_SMP )
   RTEMS_STATIC_ASSERT(



More information about the vc mailing list