RSS/Atom feed Twitter
Site is read-only, email is disabled

strict aliasing warning in build.

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

3 of 3 messages available
Toggle history

Please log in to manage your subscriptions.

strict aliasing warning in build. Patrick Horgan 01 Oct 09:46
  strict aliasing warning in build. Sven Neumann 02 Oct 00:21
   strict aliasing warning in build. Patrick Horgan 03 Oct 05:07
Patrick Horgan
2010-10-01 09:46:18 UTC (over 14 years ago)

strict aliasing warning in build.

I see this warning:

gimpcpuaccel.c: In function ‘arch_get_vendor’: gimpcpuaccel.c:182: warning: dereferencing type-punned pointer will break strict-aliasing rules

Which is gcc's way of telling you that when optimization is turned on gcc will feel free to generate code that ignores any changes you made via the type punned pointers. Although it's doing what you expect right now, you're just getting away with it--gcc on any release may break this code.

If you want more details you could look at the section I wrote about this gcc warning in:

https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines

for more information. Under the latest C++ standard rules, gcc is free to assume that in spite of the assignments:

*(int *)&id[0] = ebx; *(int *)&id[4] = edx;
*(int *)&id[8] = ecx;

id[12] = '\0';

that only the 13th byte is initialized and if it's convenient to the optimizer, throw away the results of the assignments to the type-punned pointer indirections and directly use the original values of those bytes. This would most likely result in the routine always returning:

return ARCH_X86_VENDOR_UNKNOWN;

which wouldn't be a disaster I imagine, but would interfere with your ability to do your own optimizations knowing the CPU architecture. To fix it, you could use the argument -fno-strict-aliasing to tell the optimizer never to do this sort of optimization, but then you might have worse code. The fix would be to make a union:

union { gchar idaschars[16];
int idasints[4];
} id;

and access the appropriate sections.

id.idasints[0] = ebx; id.idasints[1] = edx;
id.idasints[2] = ecx;

id.idaschars[12] = '\0';

then do the comparisons against id.idaschars.

I know this seems quite annoying and it seems that gcc should be able to see that the assignments are into the array storage area, but really, gcc is doing the right thing according to the standard which made the requirement at the request of some of the compiler companies to make a class of optimization possible.

Patrick

Sven Neumann
2010-10-02 00:21:11 UTC (over 14 years ago)

strict aliasing warning in build.

On Fri, 2010-10-01 at 00:46 -0700, Patrick Horgan wrote:

The fix would be to make a union:

union { gchar idaschars[16];
int idasints[4];
} id;

and access the appropriate sections.

id.idasints[0] = ebx; id.idasints[1] = edx;
id.idasints[2] = ecx;

id.idaschars[12] = '\0';

then do the comparisons against id.idaschars.

Could you send a patch please, preferably generated from a git commit?

Thanks, Sven

Patrick Horgan
2010-10-03 05:07:21 UTC (over 14 years ago)

strict aliasing warning in build.

On 10/01/2010 03:21 PM, Sven Neumann wrote:

On Fri, 2010-10-01 at 00:46 -0700, Patrick Horgan wrote:

The fix would be to make a union:

union { gchar idaschars[16];
int idasints[4];
} id;

and access the appropriate sections.

id.idasints[0] = ebx; id.idasints[1] = edx;
id.idasints[2] = ecx;

id.idaschars[12] = '\0';

then do the comparisons against id.idaschars.

Could you send a patch please, preferably generated from a git commit?

Ok. Attached.

Patrick