g++: infinite loop with -O3 while compiling Boost.Quickbook from Boost CVS

Bug #82404 reported by Dean Michael Berris
4
Affects Status Importance Assigned to Milestone
gcc-4.1 (Ubuntu)
Won't Fix
Medium
Unassigned

Bug Description

Binary package hint: g++-4.1

To reproduce the behaviour (in Edgy Eft), it would be best to download the Boost CVS sources from http://boost.org/ and in the tools/quickbook directory of the boost distribution, invoke `bjam release` -- this assumes bjam is installed and accessible from the path.

It is notable that the debug build compiles in a few minutes (say 5 minutes) on an Intel T2300 (Core Duo 1.68 Ghz) with 512 MB RAM and 1 GB swap, while it keeps building for more than 250 minutes in release mode (basically with the -O3 flag turned on).

I know I should be able to provide more information, but I'm not sure how to gather runtime information from the compiler. Is there more information I can provide?

Revision history for this message
Matthias Klose (doko) wrote : Re: [Bug 82404] g++: infinite loop with -O3 while compiling Boost.Quickbook from Boost CVS

Dean Michael Berris schrieb:
> Public bug reported:
>
> Binary package hint: g++-4.1
>
> To reproduce the behaviour (in Edgy Eft), it would be best to download
> the Boost CVS sources from http://boost.org/ and in the tools/quickbook
> directory of the boost distribution, invoke `bjam release` -- this
> assumes bjam is installed and accessible from the path.

No, please send the preprocessed source together with the command line
options used to compile the file.

> I know I should be able to provide more information, but I'm not sure
> how to gather runtime information from the compiler. Is there more
> information I can provide?

See http://gcc.gnu.org/bugs.html

Changed in gcc-4.1:
status: Unconfirmed → Needs Info
Revision history for this message
Dean Michael Berris (mikhailberis-gmail) wrote :

Here's the command used to invoke the build:

"g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -DBOOST_ALL_NO_LIB=1 -DNDEBUG -I"../.." -c -o "../../bin.v2/tools/quickbook/gcc-4.1.2/release/link-static/quickbook.o" "detail/quickbook.cpp"

g++ --version is:

g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I've attached the preprocessed quickbook.cpp output as requested.

Anything else I'm missing?

HTH

Revision history for this message
Matthias Klose (doko) wrote :

thanks for sending the source; confirmed for gcc-4.1; please could you recheck with new compiler versions as well (gcc-snapshot in feisty, or gcc-snapshot and g++-4.2 in gutsy)?

Changed in gcc-4.1:
importance: Undecided → Medium
Revision history for this message
Dominique Pellé (dominique-pelle) wrote :

I can reproduce this bug as well on my feisty laptop (with all updates).

Compiling with -O1 works:

pel@pel-laptop:/tmp$ time g++ -O1 -c -o quickbook.o quickbook.cpp

real 0m29.831s
user 0m28.926s
sys 0m0.476s

Compiling with -O2 does not seem to end (I waited 15 minutes which I assume is more than enough)

pel@pel-laptop:/tmp$ time g++ -O2 -c -o quickbook.o quickbook.cpp
(endless loop, or takes a very long time)

According to g++ man page:

           -O2 turns on all optimization flags specified by -O. It also turns
           on the following optimization flags: -fthread-jumps -fcrossjumping
           -foptimize-sibling-calls -fcse-follow-jumps -fcse-skip-blocks
           -fgcse -fgcse-lm -fexpensive-optimizations -fstrength-reduce -fre‐
           run-cse-after-loop -frerun-loop-opt -fcaller-saves -fpeephole2
           -fschedule-insns -fschedule-insns2 -fsched-interblock
           -fsched-spec -fregmove -fstrict-aliasing
           -fdelete-null-pointer-checks -freorder-blocks -freorder-functions
           -falign-functions -falign-jumps -falign-loops -falign-labels
           -ftree-vrp -ftree-pre

So I tried adding on top of -O1, all optimisation turned on by O2, in order to find the one which causes the bug.
However, adding them all on top of -O1 does not trigger the bug:

pel@pel-laptop:/tmp$ time g++ -O1 -fthread-jumps -fcrossjumping -foptimize-sibling-calls -fcse-follow-jumps -fcse-skip-blocks -fgcse -fgcse-lm -fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop -frerun-loop-opt -fcaller-saves -fpeephole2 -fschedule-insns -fschedule-insns2 -fsched-interblock -fsched-spec -fregmove -fstrict-aliasing -fdelete-null-pointer-checks -freorder-blocks -freorder-functions -falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp -ftree-pre -c -o quickbook.o quickbook.cpp

real 0m39.420s
user 0m38.382s
sys 0m0.560s

Does it mean -O2 turns on optimisations that are not documented in g++ man page?

Revision history for this message
Dominique Pellé (dominique-pelle) wrote :

I added #if 0 around blocks of code to find which piece of code triggers the bug.

By trial an error, I found out that 'gcc -O2' compile successfully if I comment the following lines:

96297 #if 0
96298 parse_info<iterator_type> info = parse(first, last, l);
96299
96300 if (info.hit || ignore_docinfo)
96301 {
96302 pre(actor.out, actor, ignore_docinfo);
96303
96304 block_grammar<actions> g(actor);
96305 info = parse(info.hit ? info.stop : first, last, g);
96306 if (info.full)
96307 {
96308 post(actor.out, actor, ignore_docinfo);
96309 }
96310 }
96311
96312 if (!info.full)
96313 {
96314 file_position const pos = info.stop.get_position();
96315 detail::outerr(pos.file,pos.line)
96316 << "Syntax Error near column " << pos.column << ".\n";
96317 return 1;
96318 }
96319 #endif

pel@pel-laptop:/tmp$ time g++ -O2 -c -o quickbook.o quickbook.cpp

real 0m5.072s
user 0m4.880s
sys 0m0.192s

But if I move the '#if 0' only one line below (as follows) then 'gcc -O2' loops forever:

96297 parse_info<iterator_type> info = parse(first, last, l);
96298 #if 0
96299
96300 if (info.hit || ignore_docinfo)
96301 {
96302 pre(actor.out, actor, ignore_docinfo);
96303
96304 block_grammar<actions> g(actor);
96305 info = parse(info.hit ? info.stop : first, last, g);
96306 if (info.full)
96307 {
96308 post(actor.out, actor, ignore_docinfo);
96309 }
96310 }
96311
96312 if (!info.full)
96313 {
96314 file_position const pos = info.stop.get_position();
96315 detail::outerr(pos.file,pos.line)
96316 << "Syntax Error near column " << pos.column << ".\n";
96317 return 1;
96318 }
96319 #endif

So it seems to be the template...

96297 parse_info<iterator_type> info = parse(first, last, l);

... which is triggering the bug.

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

[Expired for gcc-4.1 (Ubuntu) because there has been no activity for 60 days.]

Revision history for this message
Dominique Pellé (dominique-pelle) wrote :

I still observe this bug in Gutsy which uses gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
Compiling the previous attached preprocessed quickbook.cpp does not seem to end when compiled with -O2 or -O3.

pel@pel-laptop:~$ gcc -O2 quickbook.cpp
... does not seem to end...

Revision history for this message
Dominique Pellé (dominique-pelle) wrote :

I change status to Confirmed since I still see this bug with Gutsy release (very easy to reproduce with attached preprocessed quickbook.cpp source file)

Changed in gcc-4.1:
status: Invalid → Confirmed
Revision history for this message
Matthias Klose (doko) wrote :

can't reproduce with 4.3 and 4.4. closing as won't fix.

Changed in gcc-4.1 (Ubuntu):
status: Confirmed → Won't Fix
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.