I conducted these experiments and here are the results:
+ GCC 4.4.5 in Ubuntu 10.04: NO BUG
+ GCC 4.5.2 in Ubuntu 11.04: BUG PRESENT
+ GCC 4.6.1 in Ubuntu 11.10 (alpha 3): NO BUG

Other factors:
+ The bug goes away if optimization is -O0 instead of -O3
+ The bug goes away if a do-nothing line of code is inserted to reference the 
variable "ii" whose initialization is apparently being removed with -O3 
optimization.

I was not able to make a minimal program to demonstrate the bug. The bug
went away in the minimal program. Therefore I have attached the full
application which demonstrates the bug.

How to demonstrate the bug:
0. Use Ubuntu 11.04 with GCC 4.5.2  and libgtk2.0-dev installed
1. unpack the tarball: $ tar -xzf mashup-2.9.tar.gz
2. build the application: $ cd mashup; $ make
3. run the application: $ ./mashup
4. press the toolbar button with the printer icon (3rd from last)
5. choose the last "paper format" in the drop-down list: "custom N.N x N.N cm"
6. edit this item by deleting characters from the end.
This should be permitted with no crashing.
7. $ gedit zfuncs.cc
8. search for "////".
This is a line in the function pvlist_remove(), commented "stop g++ 
optimization bug".
This is a do-nothing line of code whose purpose is to reference the variable 
"ii".
Make sure you are in pvlist_remove() since "////" is present in a few other 
places.
9. comment this line away by adding "//" before the line
10. rebuild: $ make clean; $ make
11. repeat steps 3-6. After deleting two characters, the program crashes with 
seg-fault
12. $ gedit Makefile
13. replace the GCC optimization -O3 with -O0
14. repeat steps 3-6. The bug is gone.

There is another instance of this bug in another function,
image_navi::image_navigate(). See the line of code in that function
containing the comment "stop g++ optimization bug". This is an unrelated
function demonstrating the same bug, but testing in this case is more
complex.



On 08/08/2011 03:21 PM, Matthias Klose wrote:
> - please recheck with GCC 4.5 and GCC 4.6 in oneiric.
> - please attach a self-contained example, including the command options used
> - include the warnings building the file.
>
> ** Changed in: gcc-defaults (Ubuntu)
>         Status: New =>  Incomplete
>

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/817768

Title:
  GCC optimizer removes necessary code

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/817768/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to