Changeset 80ad7090 in rtems


Ignore:
Timestamp:
Sep 8, 2014, 12:13:31 PM (6 years ago)
Author:
Pavel Pisa <pisa@…>
Branches:
4.11, 5, master
Children:
8028089
Parents:
6821a629
git-author:
Pavel Pisa <pisa@…> (09/08/14 12:13:31)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/08/14 12:17:04)
Message:

score: More strict RTEMS_DEQUALIFY implementation.

This implementation is able to catch cast to type
which differs not only in qualifiers. The error
diagnostic message when used in function is self
descriptive. Macro is compatible with used in initializers
but there message about not constant initial value
signals types incompatibility.

The actual implementation does not distinguish between
volatile and const removal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/basedefs.h

    r6821a629 r80ad7090  
    192192 *  in a variable argument method.
    193193 */
    194 #if defined(__GNUC__)       
     194#if defined(__GNUC__)
    195195  #define RTEMS_COMPILER_UNUSED_ATTRIBUTE __attribute__((unused))
    196196#else
     
    228228  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
    229229
     230#ifdef __cplusplus
     231#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
     232            (const_cast<_type>( _var ))
     233#else /* Standard C code */
     234
     235/* The reference type idea based on libHX by Jan Engelhardt */
     236#define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
     237  typeof(_ptr_level(union { int z; typeof(_ptr_type) x; }){0}.x)
     238
     239#if defined(__GNUC__) && !defined(ASM)
     240#if  ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
     241extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
     242  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
     243#else
     244extern void RTEMS_DEQUALIFY_types_not_compatible(void);
     245#endif
     246#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
     247    __builtin_choose_expr( __builtin_types_compatible_p ( \
     248        RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
     249        RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
     250      ) || __builtin_types_compatible_p ( _type, void * ), \
     251    (_type)(_var), \
     252    RTEMS_DEQUALIFY_types_not_compatible() \
     253  ) \
     254)
     255#endif /*__GNUC__*/
     256#endif /*__cplusplus*/
     257
     258#ifndef RTEMS_DECONST
     259#ifdef RTEMS_DEQUALIFY_DEPTHX
     260#define RTEMS_DECONST( _type, _var ) \
     261  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
     262#else /*RTEMS_DEQUALIFY_DEPTHX*/
    230263/**
    231264 * @brief Removes the const qualifier from a type of a variable.
     
    237270  ((_type)(uintptr_t)(const void *) ( _var ))
    238271
     272#endif /*RTEMS_DEQUALIFY_DEPTHX*/
     273#endif /*RTEMS_DECONST*/
     274
     275#ifndef RTEMS_DEVOLATILE
     276#ifdef RTEMS_DEQUALIFY_DEPTHX
     277#define RTEMS_DEVOLATILE( _type, _var ) \
     278  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
     279#else /*RTEMS_DEQUALIFY_DEPTHX*/
    239280/**
    240281 * @brief Removes the volatile qualifier from a type of a variable.
     
    246287  ((_type)(uintptr_t)(volatile void *) ( _var ))
    247288
     289#endif /*RTEMS_DEQUALIFY_DEPTHX*/
     290#endif /*RTEMS_DEVOLATILE*/
     291
     292#ifndef RTEMS_DEQUALIFY
     293#ifdef RTEMS_DEQUALIFY_DEPTHX
     294#define RTEMS_DEQUALIFY( _type, _var ) \
     295  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
     296#else /*RTEMS_DEQUALIFY_DEPTHX*/
    248297/**
    249298 * @brief Removes the all qualifiers from a type of a variable.
     
    254303#define RTEMS_DEQUALIFY( _type, _var ) \
    255304  ((_type)(uintptr_t)(const volatile void *) ( _var ))
     305
     306#endif /*RTEMS_DEQUALIFY_DEPTHX*/
     307#endif /*RTEMS_DEQUALIFY*/
    256308
    257309#ifndef ASM
Note: See TracChangeset for help on using the changeset viewer.