From: Sam S. <sd...@gn...> - 2017-02-27 18:12:27
|
Hi Bruno, > * Bruno Haible <oe...@py...t> [2017-02-26 18:44:58 +0100]: > > You wrote in > <https://sourceforge.net/p/clisp/mailman/message/35687181/>: Do you have code to get this reference automatically? >> It dawned on me that this might be an aliasing issue. The pointer >> derived from ((unsigned long)STACK[-1-(long)(2+4+2*kept_slots)]-1UL) >> is visible in this scope twice, once cast to an Instance (pointer to >> an anonymous struct) and once cast to a Record (record_ *). I tried >> building with -fno-strict-aliasing and sure enough, the build >> succeeded. > > Wow! You hit the nail on the head. Without posting any (or at least not much) assembly, could you please explain what gcc does with -fstrict-aliasing? Specifically, I always thought that float f; unsigned int i = *(unsigned int *)&f; is compiled to an inline memcpy or something. what does gcc do instead when it detects aliasing? (you can assume that I read http://stackoverflow.com/q/98650/850781 and http://stackoverflow.com/q/98340/850781 carefully, but no more than that). > --- a/src/makemake.in Sun Feb 26 18:27:03 2017 +0100 > +++ b/src/makemake.in Sun Feb 26 18:30:41 2017 +0100 > @@ -1325,6 +1327,23 @@ > > fi > > +# We access the same memory through pointers of different types, for example > +# as TheVarobject(obj)->..., TheRecord(obj)->..., TheInstance(obj)->... . > +# This violates the strict type-based aliasing rules of C. In other words, we > +# still use C as a portable assembler, but now the compilers want to outsmart > +# us. There are two ways to tell them not to do this: to use union types, or > +# specific compiler options. I prefer to do it through compiler options. > +if [ $XCC_GCC = true ] ; then > + XCFLAGS=$XCFLAGS' -fno-strict-aliasing' > +else > + if [ "$HSYSOS" = aix ] ; then # for xlc > + XCFLAGS=$XCFLAGS' -qalias=noansi' > + fi > + if [ -n "$XCC_SUNPRO" ] ; then # for SUNWspro cc > + XCFLAGS=$XCFLAGS' -xalias_level=weak' > + fi > +fi > + > if [ "${with_dynamic_modules}" != no ]; then # not on msvc > # Support for dynamic loading. > eval "`./libtool --tag=CC --config | grep '^pic_flag='`" shouldn't it be something like --8<---------------cut here---------------start------------->8--- diff -r 208ade5c97ca src/makemake.in --- a/src/makemake.in Sun Feb 26 20:07:47 2017 -0500 +++ b/src/makemake.in Mon Feb 27 13:05:45 2017 -0500 @@ -1335,13 +1335,12 @@ fi # specific compiler options. I prefer to do it through compiler options. if [ $XCC_GCC = true ] ; then XCFLAGS=$XCFLAGS' -fno-strict-aliasing' -else - if [ "$HSYSOS" = aix ] ; then # for xlc +elif [ "$HSYSOS" = aix ] ; then # for xlc XCFLAGS=$XCFLAGS' -qalias=noansi' - fi - if [ -n "$XCC_SUNPRO" ] ; then # for SUNWspro cc +elif [ -n "$XCC_SUNPRO" ] ; then # for SUNWspro cc XCFLAGS=$XCFLAGS' -xalias_level=weak' - fi +elif [ "${with_debug}" != no ]; then + echo "$0: WARNING: how to disable strict aliasing with ${XCC} on ${HSYSOS}?" >&2 fi if [ "${with_dynamic_modules}" != no ]; then # not on msvc --8<---------------cut here---------------end--------------->8--- -- Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504 http://steingoldpsychology.com http://www.childpsy.net http://memri.org http://think-israel.org http://camera.org http://www.dhimmitude.org He who laughs last did not get the joke. |