This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/42103] [4.4 regression] packed 64-bit field reports as violation of strict aliasing rules
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Nov 2009 17:29:49 -0000
- Subject: [Bug middle-end/42103] [4.4 regression] packed 64-bit field reports as violation of strict aliasing rules
- References: <bug-42103-18460@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from rguenth at gcc dot gnu dot org 2009-11-21 17:29 -------
static inline void put_unaligned_uint64(void *p, uint64_t datum)
{
struct { uint64_t d; } __attribute__((packed)) *pp = p;
pp->d = datum;
}
int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie,
unsigned char version, uint64_t value)
{
struct _local {
unsigned char version;
uint64_t value;
} __attribute__((packed)) newval = { version, };
put_unaligned_uint64(&newval.value, htonll(value));
return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
}
This code accesses an object of type uint64_t via a pointer to a
struct containing an uint64_t which is an alias violation.
I don't see put_unaligned_uint32 being used, and only in the context
of the use of put_unaligned_uint64 it is appearant to the compiler
that you violate C aliasing rules.
You probably instead want to use sth like
typedef uint64_t __attribute__((aligned(1))) unaligned_uint64_t;
static inline void put_unaligned_uint64(void *p, uint64_t datum)
{
unaligned_uint64_t *pp = p;
*pp = datum;
}
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42103