After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 615672 - cant' compile mutter error: dereferencing pointer ‘p’ does break strict-aliasing rules
cant' compile mutter error: dereferencing pointer ‘p’ does break strict-alia...
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
git master
Other Linux
: Normal blocker
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2010-04-13 18:13 UTC by Diska
Modified: 2010-04-15 02:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Avoid triggering strict-aliasing checks when iterating preferences (4.28 KB, patch)
2010-04-13 18:45 UTC, Owen Taylor
none Details | Review
Avoid triggering strict-aliasing checks when iterating preferences (4.92 KB, patch)
2010-04-13 19:49 UTC, Owen Taylor
none Details | Review
Avoid triggering strict-aliasing checks when iterating preferences (4.88 KB, patch)
2010-04-13 21:44 UTC, Owen Taylor
committed Details | Review
Avoid triggering strict-aliasing checks when iterating preferences (19.51 KB, patch)
2010-04-13 21:56 UTC, Owen Taylor
none Details | Review

Description Diska 2010-04-13 18:13:54 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
Comment 1 Diska 2010-04-13 18:26:50 UTC
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
Comment 2 Owen Taylor 2010-04-13 18:45:08 UTC
Created attachment 158633 [details] [review]
Avoid triggering strict-aliasing checks when iterating preferences

Can you test the attached patch and see if it helps?
Comment 3 Diska 2010-04-13 18:59:04 UTC
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
Comment 4 Owen Taylor 2010-04-13 19:29:22 UTC
(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?
Comment 5 Owen Taylor 2010-04-13 19:49:59 UTC
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.)
Comment 6 Diska 2010-04-13 20:41:42 UTC
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
Comment 7 Diska 2010-04-13 21:00:19 UTC
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.
Comment 8 Diska 2010-04-13 21:00:32 UTC
via http://gcc.gnu.org/gcc-4.4/porting_to.html
Comment 9 Owen Taylor 2010-04-13 21:44:05 UTC
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.
Comment 10 Owen Taylor 2010-04-13 21:56:51 UTC
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.
Comment 11 Owen Taylor 2010-04-14 12:20:10 UTC
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.
Comment 12 Tomas Frydrych 2010-04-14 12:30:08 UTC
I would say go with the char** version, trying to work out what exactly gcc is up to is probably not worth the effort.
Comment 13 Diska 2010-04-14 16:10:34 UTC
attach id=158652 of comment #10 work for me
Comment 14 Owen Taylor 2010-04-14 16:24:29 UTC
(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)
Comment 15 Diska 2010-04-14 16:30:25 UTC
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
Comment 16 Diska 2010-04-14 16:31:43 UTC
i tried only the patch id=158652 at #10
Comment 17 Owen Taylor 2010-04-15 02:19:41 UTC
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