[U-Boot] [PATCH] dlmalloc.c: Fix gcc alias warning

Alexander Stein alexander.stein at systec-electronic.com
Thu Oct 14 08:50:29 CEST 2010


Hello,

On Thursday 14 October 2010, 08:41:20 Joakim Tjernlund wrote:
> Fix these warnings:
> dlmalloc.c: In function 'free':
> dlmalloc.c:2507: warning: dereferencing pointer '({anonymous})' does break
> strict-aliasing rules dlmalloc.c:2507: warning: dereferencing pointer
> '({anonymous})' does break strict-aliasing rules dlmalloc.c:2507: warning:
> dereferencing pointer '({anonymous})' does break strict-aliasing rules
> 
> Some
> page(http://blog.worldofcoding.com/2010/02/solving-gcc-44-strict-aliasing-
> problems.html) suggests adding __attribute__((__may_alias__)). Doing so
> makes the warnings go away. ---
>  common/dlmalloc.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/common/dlmalloc.c b/common/dlmalloc.c
> index 2276532..c78cacc 100644
> --- a/common/dlmalloc.c
> +++ b/common/dlmalloc.c
> @@ -1155,7 +1155,7 @@ struct malloc_chunk
>    INTERNAL_SIZE_T size;      /* Size in bytes, including overhead. */
>    struct malloc_chunk* fd;   /* double links -- used only if free. */
>    struct malloc_chunk* bk;
> -};
> +} __attribute__((__may_alias__)) ;
> 
>  typedef struct malloc_chunk* mchunkptr;
> 
> @@ -1443,7 +1443,7 @@ nextchunk->
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> 
>  #define NAV             128   /* number of bins */
> 
> -typedef struct malloc_chunk* mbinptr;
> +typedef struct malloc_chunk*  mbinptr __attribute__((__may_alias__));
> 
>  /* access macros */

Though I don't know the actual code why not use a union instead?

Regards,
Alexander


More information about the U-Boot mailing list