Bug 44759 - gcc crashes when compiling a program with typecasted inline function
gcc crashes when compiling a program with typecasted inline function
Status: CLOSED DUPLICATE of bug 39858
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-06-16 03:52 EDT by Hui Huang
Modified: 2007-04-18 12:33 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-06-20 20:57:39 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Hui Huang 2001-06-16 03:52:01 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.2-2 i686)

Description of problem:
gcc-2.96 shipped with Redhat-7.0, 7.1, or the latest
gcc-3.0 nightly build from gcc.gnu.org will crash
when building Hotspot Java VM. What we are trying to
do is to call an inline function with typecast,
as demonstrated in the following program:

---------------------------------- test.cpp ----
typedef void (*func_type)(long);

inline void fun(int x, int y) {}

void main(void)
{
   long tmp;
   ((func_type)fun)(tmp);
}
------------------------------------------------

Both egcs (gcc-2.91) and gcc-2.95 can compile the
above simple program correctly. But gcc-2.96 and
gcc-3.0 snapshot will crash when optimization is
enabled.


How reproducible:
Always

Steps to Reproduce:
1. save the short program in "Description" into a file
2. g++ -O test.cpp

Actual Results:  saw:~/gcc_crash> g++ -O test.cpp
In file included from test.cpp:8:
test.cpp:3: Internal error: Segmentation fault.
Please submit a full bug report.
See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions.
saw:~/gcc_crash> 


Additional info:

When it crashed, it crashed at optimize.c:467
(function initialize_inlined_parameters)

466      /* Find the initializer.  */
467      value = TREE_VALUE (a);
468      /* If the parameter is never assigned to, we may not need to 
469         create a new variable here at all.  Instead, we may be able
470         to just use the argument value.  */
471      if (TREE_READONLY (p)

At the time of crash, a is NULL.
Comment 1 Ben Greear 2001-06-20 20:56:39 EDT
I see something similar when passing the output of an inline method
to the htonl() macro.  The code snippet below has comments showing
the bug and work-around.

Compiling with -O2 (C++) causes the segv.

if (mudlog.ofLevel(DBG2)) {
   uint16 tmp = getDestIP(); //NOTE: Fixes COMPILER SEGV
   VLOG << "sending udp packet to dst_addr :" << toStringIP(getDestIP())
        << endl;
   VLOG << "sending udp packet to dst_addr network byte order:" 
        << toStringIP(htonl(tmp)) << endl;
   //   << toStringIP(htonl(getDestIP())) << endl; // Causes compiler to SEGV
   VLOG << "sending udp packet to dst_ip_port :" << getDestIPPort() << endl;
}
Comment 2 Ben Greear 2001-06-20 20:57:35 EDT
I see something similar when passing the output of an inline method
to the htonl() macro.  The code snippet below has comments showing
the bug and work-around.

Compiling with -O2 (C++) causes the segv.

if (mudlog.ofLevel(DBG2)) {
   uint16 tmp = getDestIP(); //NOTE: Fixes COMPILER SEGV
   VLOG << "sending udp packet to dst_addr :" << toStringIP(getDestIP())
        << endl;
   VLOG << "sending udp packet to dst_addr network byte order:" 
        << toStringIP(htonl(tmp)) << endl;
   //   << toStringIP(htonl(getDestIP())) << endl; // Causes compiler to SEGV
   VLOG << "sending udp packet to dst_ip_port :" << getDestIPPort() << endl;
}
Comment 3 Jakub Jelinek 2001-06-22 06:32:54 EDT
I've fixed it some time ago in gcc-c++-2.96-86. Since that gcc rpm
on, it will print a warning like:
UU.C:8: warning: too few arguments passed to inline void fun (int,
int), suppressing inlining
egcs or g++ 2.95.x did not crash because it would not try to inlining
it at all.
Anyway, the "optimization" is flawed, if you were not doing the
typecasting and passed correct number of arguments, you'd get
better code with gcc 2.96 or 3.0 (the call would get inlined).

*** This bug has been marked as a duplicate of 39858 ***

Note You need to log in before you can comment on or make changes to this bug.