Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017 Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
<== Date ==> <== Thread ==>

Subject: Re: warnings about strict aliasing
From: Benjamin Franksen <benjamin.franksen@helmholtz-berlin.de>
To: "core-talk@aps.anl.gov" <core-talk@aps.anl.gov>
Date: Fri, 1 Dec 2017 13:10:41 +0100
On 11/30/2017 05:30 PM, Michael Davidsaver wrote:
> On 11/30/2017 06:33 AM, Dirk Zimoch wrote:
>> On 29.11.2017 20:51, Michael Davidsaver wrote: I will do some tests
>> to find out if I can remove the warnings. If not, I will add the
>> -fno-strict-aliasing compiler option to my architectures which use
>> older compilers and to the vxWorks configuration in EPICS.
> 
> Fair enough for PSI, though to be clear I wouldn't want this in Base
> without some identified mis-behavior. I've read a lot of people
> worrying theoretically about -fstrict-aliasing, but the only specific
> cases of actual mis-behavior I can find have to do with cases where a
> function has two pointer arguments of different types, which happen
> to point to the same memory.

In our control system we had a case of a function misbehaving due to
strict aliasing. The code was this (yes, this is a horrible hack):

long castToFloat(struct subRecord *psub)
{
    long lval = psub->a;
    psub->val = *((float*)(&lval));
    return(0);
}

The cross-compilers for RTEMS-4.9 (gcc 4.3.2) and RTEMS-4.10 (gcc 4.4.7)
show the warning and generate code that does not behave as intended.
Changing it to

long castToFloat(struct subRecord *psub)
{
    union {
        epicsInt32 lval;
        float fval;
    } lorf;
    lorf.lval = psub->a;
    psub->val = lorf.fval;
}

made the warning go away and repaires the intended behavior (whatever
that may be; the only thing I know is that the code worked on our
ancient cross-compiler for VxWorks-5.4.2).

Cheers
Ben
-- 
"Make it so they have to reboot after every typo." ― Scott Adams

Attachment: signature.asc
Description: OpenPGP digital signature


References:
warnings about strict aliasing Dirk Zimoch
Re: warnings about strict aliasing Michael Davidsaver
Re: warnings about strict aliasing Dirk Zimoch
Re: warnings about strict aliasing Michael Davidsaver

Navigate by Date:
Prev: Re: EPICS 7 Documentation or just README.examples for the V4 part. Marty Kraimer
Next: Re: EPICS 7 Documentation or just README.examples for the V4 part. Williams Jr., Ernest L.
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
Navigate by Thread:
Prev: Re: warnings about strict aliasing Michael Davidsaver
Next: EPICS 7 vxWorks diff Dirk Zimoch
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <2017
ANJ, 01 Dec 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·