[PATCH 32/32] score: remove part of an assertion that cannot compile with Clang

Sebastian Huber sebastian.huber at embedded-brains.de
Fri May 12 05:50:58 UTC 2017


On 11/05/17 16:26, Daniel Hellstrom wrote:
> From: Jacob Hansen <jacob.hansen at gaisler.com>
>
> ---
>   cpukit/score/include/rtems/score/threadqimpl.h | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
> index 574221c..975221c 100644
> --- a/cpukit/score/include/rtems/score/threadqimpl.h
> +++ b/cpukit/score/include/rtems/score/threadqimpl.h
> @@ -1140,9 +1140,7 @@ typedef struct {
>   #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
>     RTEMS_STATIC_ASSERT( \
>       offsetof( object_type, wait_queue_member ) \
> -      == offsetof( Thread_queue_Object, Wait_queue ) \
> -    && ( &( ( (object_type *) 0 )->wait_queue_member ) \
> -      == ( &( (Thread_queue_Object *) 0 )->Wait_queue ) ), \
> +      == offsetof( Thread_queue_Object, Wait_queue ), \
>       object_type \
>     )
>   

This assertion checks two things.

1. That the member offset of both structures is equal.

2. That the type of the members is identical.

You remove (2). A quick test of

struct s {
     int i;
};

_Static_assert(__builtin_types_compatible_p(__typeof(((struct s 
*)0)->i), int), "s");

struct t {
     int i;
};

_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");

struct u {
     int i;
};

_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");

with clang results in

clang -S test.c -o -
test.c:11:16: error: static_assert expression is not an integral 
constant expression
_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:11:19: note: cast that performs the conversions of a 
reinterpret_cast is not allowed in a constant expression
_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");
                   ^
test.c:17:16: error: static_assert expression is not an integral 
constant expression
_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:17:35: note: cannot access field of null pointer
_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");
                                   ^
2 errors generated.

with gcc results in

gcc -S -o - test.c -std=c11
         .file   "test.c"
         .ident  "GCC: (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch 
revision 202388]"
         .section        .note.GNU-stack,"", at progbits

So, maybe use |__builtin_types_compatible_p() and typeof (should be done 
via <rtems/score/basedefs.h>). Maybe ask on the LLVM mailing list on how 
to check structure member types.

|

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list