GNOME Bugzilla – Bug 615672
cant' compile mutter error: dereferencing pointer ‘p’ does break strict-aliasing rules
Last modified: 2010-04-15 02:19:45 UTC
i'm trying to compile gnome-shell via jhbuild. when jhbuild try to compile mutter it's fail. cc1: warnings being treated as errors core/prefs.c: In function ‘meta_prefs_override_preference_location’: core/prefs.c:1126: error: dereferencing pointer ‘p’ does break strict-aliasing rules core/prefs.c:1129: error: dereferencing pointer ‘p’ does break strict-aliasing rules core/prefs.c:1193: note: initialized from here core/prefs.c:1127: note: initialized from here i'm on ubuntu lucid
Package: gcc Priority: optional Section: devel Installed-Size: 64 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org> Architecture: i386 Source: gcc-defaults (1.93ubuntu1) Version: 4:4.4.3-1ubuntu1 Provides: c-compiler
Created attachment 158633 [details] [review] Avoid triggering strict-aliasing checks when iterating preferences Can you test the attached patch and see if it helps?
now i post all error after patch ( in commento #0 i didn't report all error ) cc1: warnings being treated as errors core/prefs.c: In function ‘meta_prefs_override_preference_location’: core/prefs.c:1131: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1128: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1127: note: initialized from here core/prefs.c:1131: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1128: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1127: note: initialized from here core/prefs.c:1131: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1128: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1127: note: initialized from here core/prefs.c:1131: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1128: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1127: note: initialized from here core/prefs.c:1156: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1154: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1151: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1150: note: initialized from here core/prefs.c:1156: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1154: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1151: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1150: note: initialized from here core/prefs.c:1156: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1154: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1151: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1150: note: initialized from here core/prefs.c:1156: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1154: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1151: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1150: note: initialized from here make[4]: *** [prefs.o] Errore 1 make[4]: uscita dalla directory «/home/diska/gnome-shell/source/mutter/src» make[3]: *** [all-recursive] Errore 1 make[3]: uscita dalla directory «/home/diska/gnome-shell/source/mutter/src» make[2]: *** [all] Errore 2 make[2]: uscita dalla directory «/home/diska/gnome-shell/source/mutter/src» make[1]: *** [all-recursive] Errore 1 make[1]: uscita dalla directory «/home/diska/gnome-shell/source/mutter» make: *** [all] Errore 2
(In reply to comment #3) > now i post all error after patch ( in commento #0 i didn't report all error ) Is this with my new patch or not?
Created attachment 158642 [details] [review] Avoid triggering strict-aliasing checks when iterating preferences Judging from the line numbers, the last set of warnings probably was from my patch, so here's another attempt (basically trying things at random.)
error with latest patch cc1: warnings being treated as errors core/prefs.c: In function ‘meta_prefs_override_preference_location’: core/prefs.c:1139: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1136: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1135: note: initialized from here core/prefs.c:1139: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1136: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1135: note: initialized from here core/prefs.c:1139: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1136: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1135: note: initialized from here core/prefs.c:1139: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1136: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1135: note: initialized from here core/prefs.c:1164: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1162: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1159: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1158: note: initialized from here core/prefs.c:1164: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1162: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1159: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1158: note: initialized from here core/prefs.c:1164: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1162: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1159: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1158: note: initialized from here core/prefs.c:1164: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1162: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1159: error: dereferencing pointer ‘pref’ does break strict-aliasing rules core/prefs.c:1158: note: initialized from here make[4]: *** [prefs.o] Errore 1
if can help Stricter aliasing requirements GCC warns about more cases of type-punning while optimizing, like the following. struct A { char data[14]; int i; }; void foo() { char buf[sizeof(struct A)]; ((struct A*)buf)->i = 4; } Now produces the following diagnostic: warning: dereferencing type-punned pointer will break strict-aliasing rules This can be temporarily worked around by using -fno-strict-aliasing or by ignoring this class of warning via -Wno-strict-aliasing. To fix, access the structure from pointers of an equivalent type, use a union, use memcpy, or (if using C++) use placement new. See the section titled "Casting does not work as expected when optimization is turned on" on bug reporting documentation page for more information.
via http://gcc.gnu.org/gcc-4.4/porting_to.html
Created attachment 158651 [details] [review] Avoid triggering strict-aliasing checks when iterating preferences Thanks for the links; I'm pretty familiar with the strict-aliasing idea, I just can never guess when GCC will be unhappy or not. And for some reason Metacity isn't triggering these warnings for me, though I can get the same warnings with artificial test cases. In terms of the suggestions. -fno-strict-aliasing -Wno-strict-aliasing I don't like these options, since in *theory* both the optimization and the warnings are good thing and they affect the entire programs. Suggested "right way to do it" Useless here The basic problem is GCC is being too clever for its own good. There's no conceivable optimization it could be making based on strict-aliasing in this case that would be a problem, but it happens in this narrow case to be able to track variable assignment and say "hey, you are doing something invalid here". If key_is_used/do_override were in another compilation unit, it would be blissfully ignorant. Here's one more try; based on the artificial test cases, I think GCC might not complain about this, but maybe I should just give up and write things in a clumsier way.
Created attachment 158652 [details] [review] Avoid triggering strict-aliasing checks when iterating preferences Here's another version that's a little less hacky (avoids casing to a char **) and also longer. I'm not sure it's any more theoretically sound from GCC's perspective than any of the others, but if the previous patch defeats the checks this should work as well.
Reported testing on IRC: <Vamp898> owen: ok the first patch work fine. The second patch not <owen> Vamp898: what happens with the second patch? similar compilation warnings/errors as without the patch? <Vamp898> yes seems to be the same compilation errors than before (Where the first patch is the version that casts to char **, and the second patch the patch that embeds MetaBasePreference in each preference structure) I don't understand why casting to the type of the first type is OK when the first type is char *, and not when it is MetaBasePreference, so this probably just reflects GCC giving up in the char ** case. I'm inclined to with with the char ** version, as ugly as it is, and revisit this when GCC gets "smarter" again.
I would say go with the char** version, trying to work out what exactly gcc is up to is probably not worth the effort.
attach id=158652 of comment #10 work for me
(In reply to comment #13) > attach id=158652 of comment #10 work for me Do you mean that the comment #9 and comment #10 patches both work for you, or only the comment #10 one? (Since the previous report was only the comment #9 patch worked)
after mutter build with patch id=158652 gnome-shell give me warning above, i don't know if is related so i post here before post to gnome-shell GEN gnome-shell GEN St-1.0.gir GEN Shell-0.1.gir (mutter:23673): GLib-GObject-WARNING **: invalid (NULL) pointer instance (mutter:23673): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed GEN Shell-0.1.typelib GEN St-1.0.typelib GEN Gdm-1.0.gir GEN Gdm-1.0.typelib
i tried only the patch id=158652 at #10
I've gone with the char ** version - it's ugly, but simple and everybody seems to agree that it works. Attachment 158651 [details] pushed as 9915a18 - Avoid triggering strict-aliasing checks when iterating preferences