config: Fix invalid static assertions in C

Expressions in static assertions must be integral constant expressions.  In
integral constant expressions the use of address constant expressions is not
allowed.

In static initializers the address constant expressions are allowed.  Introduce
a new macro _CONFIGURE_ASSERT_NOT_NULL() which leads to a compile time error if
the second parameter is NULL.  It generates error messages like this if for
example

  #define CONFIGURE_INIT_TASK_ENTRY_POINT NULL

is provided by the application:

cpukit/include/rtems/confdefs/inittask.h:51:26: error: size of unnamed array is negative
   51 |     ( _type ) sizeof( int[ ( _value ) != NULL ? 1 : -1 ] ) )
      |                          ^
cpukit/include/rtems/confdefs/inittask.h:170:3: note: in expansion of macro '_CONFIGURE_ASSERT_NOT_NULL'
  170 |   _CONFIGURE_ASSERT_NOT_NULL(
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~

This fix relates to CID 1470570 (PARSE_ERROR).

Update #4181.
This commit is contained in:
Sebastian Huber
2020-12-12 11:35:22 +01:00
parent 9edca35dbe
commit fcd9618ac8
2 changed files with 30 additions and 31 deletions
+16 -11
View File
@@ -46,6 +46,10 @@
#ifdef CONFIGURE_INIT
#define _CONFIGURE_ASSERT_NOT_NULL( _type, _value ) \
( ( _value ) != NULL ? ( _value ) : \
( _type ) sizeof( int[ ( _value ) != NULL ? 1 : -1 ] ) )
#ifdef CONFIGURE_RTEMS_INIT_TASKS_TABLE
#include <rtems/confdefs/percpu.h>
@@ -94,8 +98,8 @@ extern "C" {
#endif
/*
* Ignore the following warnings from g++ and clang in the static assertion
* below:
* Ignore the following warnings from g++ and clang in the uses of
* _CONFIGURE_ASSERT_NOT_NULL() below:
*
* warning: the address of 'void Init()' will never be NULL [-Waddress]
*
@@ -107,13 +111,6 @@ extern "C" {
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wtautological-pointer-compare"
RTEMS_STATIC_ASSERT(
CONFIGURE_INIT_TASK_ENTRY_POINT != NULL,
CONFIGURE_INIT_TASK_ENTRY_POINT_MUST_NOT_BE_NULL
);
#pragma GCC diagnostic pop
#ifdef CONFIGURE_INIT_TASK_CONSTRUCT_STORAGE_SIZE
#ifdef CONFIGURE_INIT_TASK_STACK_SIZE
@@ -139,7 +136,10 @@ const RTEMS_tasks_User_task_config _RTEMS_tasks_User_task_config = {
CONFIGURE_INIT_TASK_INITIAL_MODES,
CONFIGURE_INIT_TASK_ATTRIBUTES,
},
CONFIGURE_INIT_TASK_ENTRY_POINT,
_CONFIGURE_ASSERT_NOT_NULL(
rtems_task_entry,
CONFIGURE_INIT_TASK_ENTRY_POINT
),
CONFIGURE_INIT_TASK_ARGUMENTS
};
@@ -167,7 +167,10 @@ const rtems_initialization_tasks_table _RTEMS_tasks_User_task_table = {
CONFIGURE_INIT_TASK_STACK_SIZE,
CONFIGURE_INIT_TASK_PRIORITY,
CONFIGURE_INIT_TASK_ATTRIBUTES,
CONFIGURE_INIT_TASK_ENTRY_POINT,
_CONFIGURE_ASSERT_NOT_NULL(
rtems_task_entry,
CONFIGURE_INIT_TASK_ENTRY_POINT
),
CONFIGURE_INIT_TASK_INITIAL_MODES,
CONFIGURE_INIT_TASK_ARGUMENTS
};
@@ -180,6 +183,8 @@ RTEMS_SYSINIT_ITEM(
#endif /* CONFIGURE_INIT_TASK_CONSTRUCT_STORAGE_SIZE */
#pragma GCC diagnostic pop
#ifdef __cplusplus
}
#endif
+14 -20
View File
@@ -139,8 +139,8 @@ const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
#if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
&& defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
/*
* Ignore the following warnings from g++ and clang in the static assertions
* below:
* Ignore the following warnings from g++ and clang in the uses of
* _CONFIGURE_ASSERT_NOT_NULL() below:
*
* warning: the address of 'f()' will never be NULL [-Waddress]
*
@@ -159,13 +159,11 @@ const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
#endif
#ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT
RTEMS_STATIC_ASSERT(
CONFIGURE_TASK_STACK_ALLOCATOR_INIT != NULL,
CONFIGURE_TASK_STACK_ALLOCATOR_INIT_MUST_NOT_BE_NULL
);
const Stack_Allocator_initialize _Stack_Allocator_initialize =
CONFIGURE_TASK_STACK_ALLOCATOR_INIT;
_CONFIGURE_ASSERT_NOT_NULL(
Stack_Allocator_initialize,
CONFIGURE_TASK_STACK_ALLOCATOR_INIT
);
RTEMS_SYSINIT_ITEM(
_Stack_Allocator_do_initialize,
@@ -174,21 +172,17 @@ const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
);
#endif
RTEMS_STATIC_ASSERT(
CONFIGURE_TASK_STACK_ALLOCATOR != NULL,
CONFIGURE_TASK_STACK_ALLOCATOR_MUST_NOT_BE_NULL
);
const Stack_Allocator_allocate _Stack_Allocator_allocate =
CONFIGURE_TASK_STACK_ALLOCATOR;
RTEMS_STATIC_ASSERT(
CONFIGURE_TASK_STACK_DEALLOCATOR != NULL,
CONFIGURE_TASK_STACK_DEALLOCATOR_MUST_NOT_BE_NULL
);
_CONFIGURE_ASSERT_NOT_NULL(
Stack_Allocator_allocate,
CONFIGURE_TASK_STACK_ALLOCATOR
);
const Stack_Allocator_free _Stack_Allocator_free =
CONFIGURE_TASK_STACK_DEALLOCATOR;
_CONFIGURE_ASSERT_NOT_NULL(
Stack_Allocator_free,
CONFIGURE_TASK_STACK_DEALLOCATOR
);
#pragma GCC diagnostic pop
#elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \