#3799 closed defect (fixed)

confdefs.h declares an array with zero elements, that's invalid C

Reported by: Jens Schweikhardt Owned by: Sebastian Huber <sebastian.huber@…>
Priority: normal Milestone:
Component: rtems Version:
Severity: normal Keywords: confdefs.h array
Cc: Blocked By:


I'm looking at rtems/cpukit/include/rtems/confdefs.h

1189	#ifdef CONFIGURE_INIT
1191	    _ISR_Stack_size,
1193	  );
1195	  char _ISR_Stack_area_begin[
1198	  RTEMS_SECTION( ".rtemsstack.interrupt.begin" );
1200	  const char _ISR_Stack_area_end[ 0 ]
1201	    RTEMS_SECTION( ".rtemsstack.interrupt.end" ) = { };
1202	#endif

Note line 1200: const char _ISR_Stack_area_end[ 0 ]
This crashes (yes, it goes boom) one of our Static Analyzer tools (Mathworks Polyspace if you must know).

According to the ISO C11 Standard, Array declarators


1 In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
an expression or *. If they delimit an expression (which specifies the size of an array), the
expression shall have an integer type. If the expression is a constant expression, it shall
have a value greater than zero.

Could this either be fixed to declare a one element array, or, if you must use 0 for some reason, be a macro that I can override for Polyspace?

Change History (11)

comment:1 Changed on Oct 4, 2019 at 1:36:37 PM by Sebastian Huber



I would write a bug report for the Mathworks Polyspace as well.

comment:2 Changed on Oct 7, 2019 at 5:07:53 AM by Sebastian Huber

Please test this patch set and check if it fixes the Mathworks Polyspace issue.

comment:3 Changed on Oct 7, 2019 at 7:16:55 AM by Jens Schweikhardt

It's difficult for me to apply the patch set since we use the RTEMS 5.x as shipped by Cobham/Gaisler? Research for their RCC 1.3-rc6-gcc. This differs enough from current RTEMS to make this a bit involved. However, I've locally patched it simply by changing [0] to [1] and Polyspace R2013a no longer crashes. I fully trust your patch set to fix this as well, so go ahead and close this as fixed. Thanks a lot for your work, Sebastian!

comment:4 Changed on Oct 9, 2019 at 2:38:45 PM by Joel Sherrill

Do you have any instructions or guidance for using Polyspace on RTEMS that could be place in the documentation?

comment:5 Changed on Oct 22, 2019 at 9:52:09 AM by Jens Schweikhardt

In general, Polyspace needs to see the same code the compiler sees. This requires that Polyspace needs to be told the compiler's predefined macros. With gcc or clang that's easy. To do that, ask for the predefined macros with $(CC) -E -dM -x c /dev/null and turn that into -D options for Polyspace.

In addition, you might want to fix/work around various language extensions Polyspace does not understand. I use

	-D __extension__=
	-D __builtin_va_list=void*
	-D __builtin_offsetof(t,m)=0
	-D _Noreturn=
	-D __restrict=

but this might need to be tweaked for your particular compiler and Polyspace release.

comment:6 Changed on Oct 28, 2019 at 9:01:58 AM by Sebastian Huber <sebastian.huber@…>

In 795b167/rtems:


Update #3799.

comment:7 Changed on Oct 28, 2019 at 9:02:01 AM by Sebastian Huber <sebastian.huber@…>

Owner: set to Sebastian Huber <sebastian.huber@…>
Resolution: fixed
Status: newclosed

In a7c86cc/rtems:

config: Avoid zero-length array


Close #3799.

comment:8 Changed on Apr 3, 2020 at 1:49:13 PM by Sebastian Huber <sebastian.huber@…>

In 8e80876/rtems:

score: Fix _ISR_Stack_area_end

The _ISR_Stack_area_begin and _ISR_Stack_area_end symbols are in
different sections. They must have the same alignment, otherwise the
following linker directive could separate them:

*(SORT_BY_ALIGNMENT (SORT_BY_NAME (.rtemsstack*)))

Update #3799.

comment:9 Changed on Apr 8, 2020 at 5:23:02 PM by Sebastian Huber <sebastian.huber@…>

In 3a882e5/rtems:

score: Add and use RTEMS_SYMBOL_NAME()

Update #3799.

comment:10 Changed on Apr 8, 2020 at 5:23:06 PM by Sebastian Huber <sebastian.huber@…>

In 099ab00/rtems:

config: Fix _ISR_Stack_area_end

In the previous implementation, the _ISR_Stack_area_begin and
_ISR_Stack_area_end symbols were in different sections. If they do not
have the same alignment, then the following linker directive could
separate them:

*(SORT_BY_ALIGNMENT (SORT_BY_NAME (.rtemsstack*)))

Do not use different sections and instead define _ISR_Stack_area_end

Update #3799.

comment:11 Changed on Apr 8, 2020 at 5:23:09 PM by Sebastian Huber <sebastian.huber@…>

In 840f21d/rtems:



Update #3799.

Note: See TracTickets for help on using tickets.