Bug 30637 - The options -fno-unit-at-a-time and -finline-functions generates erroneous code
Summary: The options -fno-unit-at-a-time and -finline-functions generates erroneous code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P3 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-30 10:22 UTC by Stefan Bylund
Modified: 2007-02-09 22:09 UTC (History)
3 users (show)

See Also:
Host: i386-linux-gnu
Target: powerpc-eabi-unknown
Build: i386-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Source code snippet test.cpp (226 bytes, text/plain)
2007-01-30 10:28 UTC, Stefan Bylund
Details
Disassembly output test.s (214 bytes, text/plain)
2007-01-30 10:29 UTC, Stefan Bylund
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Bylund 2007-01-30 10:22:29 UTC
When compiling the attached source code snippet test.cpp with the options -fno-unit-at-a-time and -finline-functions, erroneous code is produced in form of an infinite loop, see the attached disassembly file test.s.

Use the following command line to reproduce the bug:
powerpc-eabi-g++ -c -S -O2 -fno-unit-at-a-time -finline-functions -o test.s test.cpp

A possible explanation for this bug may be that -fno-unit-at-a-time counteracts -finline-functions; -finline-functions needs the whole compilation unit or more while -finline-functions says don't use the whole compilation unit.
Comment 1 Stefan Bylund 2007-01-30 10:28:12 UTC
Created attachment 12979 [details]
Source code snippet test.cpp
Comment 2 Stefan Bylund 2007-01-30 10:29:35 UTC
Created attachment 12980 [details]
Disassembly output test.s
Comment 3 Andrew Pinski 2007-01-30 10:33:23 UTC
Can you try 4.0.x or 4.1.x as 3.4.x is no longer maintained?
Comment 4 Stefan Bylund 2007-01-30 10:40:08 UTC
(In reply to comment #3)
> Can you try 4.0.x or 4.1.x as 3.4.x is no longer maintained?

Unfortunately, our system is based on GCC 3.4.x and we cannot easily switch to GCC 4.x in a short timeframe.
Comment 5 Stefan Bylund 2007-01-30 10:43:05 UTC
Comment on attachment 12980 [details]
Disassembly output test.s

>	.file	"test.cpp"
>	.section	".text"
>	.align 2
>	.globl _ZN5Actor17getResourceFacadeEv
>	.type	_ZN5Actor17getResourceFacadeEv, @function
>_ZN5Actor17getResourceFacadeEv:
>.LFB2:
>	lwz 3,0(3)
>	blr
>.LFE2:
>	.size	_ZN5Actor17getResourceFacadeEv, .-_ZN5Actor17getResourceFacadeEv
>	.align 2
>	.globl _ZN5Actor9configureEv
>	.type	_ZN5Actor9configureEv, @function
>_ZN5Actor9configureEv:
>.LFB3:
>.L3:
>	b .L3 <--------------------- ERROR: Infinite loop!
>.LFE3:
>	.size	_ZN5Actor9configureEv, .-_ZN5Actor9configureEv
>	.ident	"GCC: (GNU) 3.4.4"
Comment 6 Volker Reichelt 2007-02-09 01:16:57 UTC
The bug has nothing to do with -fno-unit-at-a-time.
(It is ignored for C++ anyways.)

The bug is fixed since GCC 4.0.0.

Btw, here's a shorter self-contained program that hangs when compiled with
"g++ -O -finline-functions" by GCC 3.4.x:

====================================
struct A
{
   virtual void FOO() {}
};

struct B
{
  A* p;

  B() : p(new A) {}

  A* foo();
  void bar();
};

A* B::foo()
{
  return p;
}

void B::bar()
{
  foo()->FOO();
}

int main()
{
  B().bar();
  return 0;
}
====================================
Comment 7 Volker Reichelt 2007-02-09 22:09:43 UTC
Sorry, I wasn't quite right with my comment:
The bug *is* related to -fno-unit-at-a-time.
It is fixed, because the flag is ignored for C++ since GCC 4.0.0,
i.e. the compiler now always uses the unit-at-a-time mode for C++.