Skip to contentSkip to conversation

dlmalloc.c: Fix gcc alias warning

PATCH Superseded Joakim Tjernlund 4 participants 6 messages Oct 14, 2010 – Oct 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dlmalloc.c: Fix gcc alias warning

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(-)
common/dlmalloc.c +2 -2
index 2276532..c78cacc 100644
@@ -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 */
 
Signature · 1 line
1.7.2.2
#1 lore raw

PATCH 1/1 dlmalloc.c: Fix gcc alias warning

Hello,

Quoted 28 lines · 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(-)
common/dlmalloc.c +1 -1
index 2276532..c78cacc 100644
@@ -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;
 

common/dlmalloc.c nextchunk-> · line 1449

Quoted 8 lines
common/dlmalloc.c +2 -1
@@ -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

#2 lore raw

PATCH 1/1 dlmalloc.c: Fix gcc alias warning

Alexander Stein <[email protected]> wrote on 2010/10/14 08:50:29:

Quoted 7 lines

Hello,

Quoted 3 lines · 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

Quoted 2 lines
Quoted 2 lines

strict-aliasing rules dlmalloc.c:2507: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules dlmalloc.c:2507:

warning:

Quoted 4 lines
Quoted 1 line

dereferencing pointer '({anonymous})' does break strict-aliasing rules

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

Me neither, you are welcome to have a crack at it.

Jocke

#3 lore raw

PATCH v2 1/1 dlmalloc.c: Fix gcc alias warning

In reply to Joakim Tjernlund

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.

---
- forgot signoff
- removed stray attribute change

 common/dlmalloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
common/dlmalloc.c +1 -1
index 2276532..77420db 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#4 lore raw

PATCH v2 1/1 dlmalloc.c: Fix gcc alias warning

Quoted 11 lines · On Thursday, October 14, 2010 02:51:34 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.

thanks ... i think this is a good stop-gap workaround

-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101014/695f94fd/attachment.pgp

#5 lore raw

PATCH v2 1/1 dlmalloc.c: Fix gcc alias warning

In reply to Joakim Tjernlund

Dear Joakim Tjernlund,

Quoted 9 lines · In message <[email protected]>…

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.

Quoted 7 lines

---
- forgot signoff
- removed stray attribute change

 common/dlmalloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Until you walk a mile in another man's moccasins, you  can't  imagine
the smell.