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

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Thu Oct 14 08:41:20 CEST 2010


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 */
 
-- 
1.7.2.2



More information about the U-Boot mailing list