This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
strict aliasing problem?
- From: "Will Lentz" <Will_Lentz at Trimble dot com>
- To: <ecos-discuss at ecos dot sourceware dot org>
- Date: Tue, 11 May 2010 09:29:15 -0700
- Subject: [ECOS] strict aliasing problem?
Hi,
I'm using GCC 4.4.1 on an MPC5200 target and I was getting incorrect
results from:
libm/current/src/double/ieee754-core/e_exp.c
Once I pass -fno-strict-aliasing to the math library, everything works
fine. (On a side note, everything works fine either way with GCC 3.3)
It looks like e_exp.c accesses the double "x" through CYG_LIBM_HI():
#define CYG_LIBM_HI(__x) (((Cyg_libm_ieee_double_shape_type
*)&__x)->parts.msw)
where Cyg_libm_ieee_double_shape_type is a union type.
According to:
http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Optimize-Options.html#index-
fstrict_002daliasing-750
code such as the following results in undefined behavior:
union a_union {
int i;
double d;
};
int f() {
double d = 3.0;
return ((union a_union *) &d)->i;
}
Should all targets use -fno-strict-aliasing when building the math
library for safety?
Thanks,
Will
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss