Optimized code fails to assign struct member

Bug #1074662 reported by Jan Wielemaker
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
gcc-4.7 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Hi,

I've upgraded to Ubuntu 12.10 on Intel i7 2600 (64-bit version) and -as a developer- compiled SWI-Prolog using
the standard gcc 4.7 compiler. All seems to work, except for the `semweb' package. It works with compiled
without optimization, but fails at -O2.

After a bit searching with gdb, it appears that a structure assignment is simply omitted. I've forced it to work
by adding a dummy function and call this using the structure field as argument.

Not sure how to report this as building the whole system is a bit work. So, I'll first provide a pointer to the
work-around commit. This can be found at the address below. The first change is irrelevant, but indicates
the location of the missing assignment.

http://www.swi-prolog.org/git/packages/semweb.git/blobdiff/192d052db9b7c44519723fa3186a5786a1562127..af7fb1bb50ec30295bc2e1a7473bbe36ee0c03bf:/rdf_db.c

The dummy function itself is simply

#if __GNUC__ == 4 && __GNUC_MINOR__ == 7
void
gcc_47_dummy(void *ptr)
{ static void *p;

  if ( p != ptr )
    p = ptr;
}
#endif

Of course, I know that adding dummy calls can make the difference without the compiler being at fault, but

  - I can see in gdb that the assignment is not done without the hack. Of course, I also know that gdb
    sometimes does weird things with optimized code. Adding a print statement fixes the problem ...
    The failed assignment does however explain subsequent (wrong) behaviour.

I'll leave it here, providing further details as deemed necessary on request.

      Thanks --- Jan

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-4.7 (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.