Bug 12315 - [3.4 Regression] ICE using -p with functions returning structs
Summary: [3.4 Regression] ICE using -p with functions returning structs
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 3.4.0
: P2 critical
Target Milestone: 3.4.0
Assignee: DJ Delorie
URL:
Keywords: ice-on-valid-code, monitored, patch
: 12421 12748 12809 12836 (view as bug list)
Depends on:
Blocks: 12421
  Show dependency treegraph
 
Reported: 2003-09-17 11:18 UTC by ishikawa,chiaki
Modified: 2004-01-17 04:22 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-10-28 22:47:42


Attachments
test case of functions that return struct values: cc1 segfaults with -p (451 bytes, text/x-csrc)
2003-09-20 18:06 UTC, ishikawa,chiaki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ishikawa,chiaki 2003-09-17 11:18:57 UTC
During bootstrap, stage1/cc1 segfaulted.


(The bug seems triggered because I am trying to build
a C compiler with -pg, gprof feature. Not many people seem
to use gprof feature of the C compiler, I am afraid, and thus it 
probably is not
exercised much.)

I hope this gets fixed soon. 

========================================
THE BUG:
----------------------------------------

stage1/xgcc -Bstage1/ -B/usr/local/i686-pc-linux-gnu/bin/ -c   -march=athlon-xp
-mtune=athlon-xp -g -pg -O2  -DIN_GCC   -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Werror
-fno-common   -DHAVE_CONFIG_H    -I. -I. -I/u2/tools/gcc-mainline-cvs/gcc/gcc
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/.
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/../include 
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c -o cppexp.o
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c: In function `num_trim':

/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c:1014: internal compiler error:
Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [cppexp.o] Error 1
make[2]: Leaving directory `/u2/tools/gcc-mainline-obj-dir/gcc'
make[1]: *** [stage2_build] Error 2
make[1]: Leaving directory `/u2/tools/gcc-mainline-obj-dir/gcc'
make: *** [bootstrap] Error 2


========================================
Quote from GDB session:
----------------------------------------
I checked the value of svrtx using gdb, and
found that it is 0 (NULL) and GET_CODE(svrtx) is called.


ishikawa@duron$  stage1/cc1 -quiet -v -I. -I.
-I/u2/tools/gcc-mainline-cvs/gcc/gcc -I/u2/tools/gcc-mainline-cvs/gcc/gcc/.
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/../include -iprefix
/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/
-isystem include -isystem stage1/include -isystem
/usr/local/i686-pc-linux-gnu/bin/include -DIN_GCC -DHAVE_CONFIG_H
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c -quiet -dumpbase cppexp.c
-march=athlon-xp -mtune=athlon-xp -auxbase-strip cppexp.o -g -O2 -W -Wall
-Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic
-Wno-long-long -Werror -version -p -fno-common -o /tmp/ccTCMJqs.s
ignoring nonexistent directory "stage1/include"
ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/bin/include"
ignoring nonexistent directory
"/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory
"/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/../../../../i686-pc-linux-gnu/include"
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory "/usr/local/lib/../i686-pc-linux-gnu/include"
ignoring duplicate directory "."
ignoring duplicate directory "/u2/tools/gcc-mainline-cvs/gcc/gcc/."
#include "..." search starts here:
#include <...> search starts here:
 .
 /u2/tools/gcc-mainline-cvs/gcc/gcc
 /u2/tools/gcc-mainline-cvs/gcc/gcc/../include
 include
 /usr/local/include
 /usr/include
End of search list.
GNU C version 3.4 20030916 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c: In function `num_trim':

/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c:1014: internal compiler error:
Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
ishikawa@duron$ gdb stage1/cc1
GNU gdb 5.3-debian
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...
Breakpoint 1 at 0x814f12c: file /u2/tools/gcc-mainline-cvs/gcc/gcc/diagnostic.c,
line 593.
Breakpoint 2 at 0x8049804
Breakpoint 3 at 0x80495a4
(gdb) run   -quiet -v -I. -I. -I/u2/tools/gcc-mainline-cvs/gcc/gcc
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/.
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/../include -iprefix
/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/
-isystem include -isystem stage1/include -isystem
/usr/local/i686-pc-linux-gnu/bin/include -DIN_GCC -DHAVE_CONFIG_H
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c -quiet -dumpbase cppexp.c
-march=athlon-xp -mtune=athlon-xp -auxbase-strip cppexp.o -g -O2 -W -Wall
-Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic
-Wno-long-long -Werror -version -p -fno-common -o /tmp/ccTCMJqs.s
Starting program: /u2/tools/gcc-mainline-obj-dir/gcc/stage1/cc1 -quiet -v -I.
-I. -I/u2/tools/gcc-mainline-cvs/gcc/gcc -I/u2/tools/gcc-mainline-cvs/gcc/gcc/.
-I/u2/tools/gcc-mainline-cvs/gcc/gcc/../include -iprefix
/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/
-isystem include -isystem stage1/include -isystem
/usr/local/i686-pc-linux-gnu/bin/include -DIN_GCC -DHAVE_CONFIG_H
/u2/tools/gcc-mainline-cvs/gcc/gcc/cppexp.c -quiet -dumpbase cppexp.c
-march=athlon-xp -mtune=athlon-xp -auxbase-strip cppexp.o -g -O2 -W -Wall
-Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic
-Wno-long-long -Werror -version -p -fno-common -o /tmp/ccTCMJqs.s
Breakpoint 2 at 0x4004b81e
Breakpoint 3 at 0x4004a8c0
ignoring nonexistent directory "stage1/include"
ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/bin/include"
ignoring nonexistent directory
"/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory
"/u2/tools/gcc-mainline-obj-dir/gcc/stage1/../lib/gcc/i686-pc-linux-gnu/3.4/../../../../i686-pc-linux-gnu/include"
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory "/usr/local/lib/../i686-pc-linux-gnu/include"
ignoring duplicate directory "."
ignoring duplicate directory "/u2/tools/gcc-mainline-cvs/gcc/gcc/."
#include "..." search starts here:
#include <...> search starts here:
 .
 /u2/tools/gcc-mainline-cvs/gcc/gcc
 /u2/tools/gcc-mainline-cvs/gcc/gcc/../include
 include
 /usr/local/include
 /usr/include
End of search list.
GNU C version 3.4 20030916 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

Program received signal SIGSEGV, Segmentation fault.
0x081c67b5 in profile_function (file=0x86660a0)
    at /u2/tools/gcc-mainline-cvs/gcc/gcc/final.c:1440
1440	  if (sval && GET_CODE (svrtx) == REG)
(gdb) list
1435	    }
1436	
1437	  function_section (current_function_decl);
1438	
1439	#if defined(ASM_OUTPUT_REG_PUSH)
1440	  if (sval && GET_CODE (svrtx) == REG)
1441	    ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
1442	#endif
1443	
1444	#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
(gdb) print sval
$1 = 1
(gdb) print svrtx
$2 = 0x0
(gdb) quit
A debugging session is active.
Do you still want to close the debugger?(y or n) y
ishikawa@duron$ 

cf.
Quote from "pr -n cppexp.c":
  995	/* Clears the unused high order bits of the number pointed to by PNUM.  */
  996	static cpp_num
  997	num_trim (cpp_num num, size_t precision)
  998	{
  999	  if (precision > PART_PRECISION)
 1000	    {
 1001	      precision -= PART_PRECISION;
 1002	      if (precision < PART_PRECISION)
 1003		num.high &= ((cpp_num_part) 1 << precision) - 1;
 1004	    }
 1005	  else
 1006	    {
 1007	      if (precision < PART_PRECISION)
 1008		num.low &= ((cpp_num_part) 1 << precision) - 1;
 1009	      num.high = 0;
 1010	    }
 1011	
 1012	  return num;
 1013	}
 1014	




This is how I configured GCC for bootstrap.
(I updated my local source CVS tree a few hours ago.)

:
#
set -vx

LANG=C
LC_ALL=C
export LANG
export LC_ALL

make distclean clean

rm config.cache

#
#--enable-languages=c
#
# Use absolute pathnaes
# env CC=gcc-cvs
#
env CC=gcc /u2/tools/gcc-mainline-cvs/gcc/configure  \
	--enable-languages=c,c++,objc	\
	--program-suffix=-mainline-cvs --enable-nls
#
#env CC=gcc-cvs make BOOT_CFLAGS="-g -pg -O2 -ftest-coverage -fprofile-arcs"
bootstrap
# doesn't work
#
env CC="gcc" make BOOT_CFLAGS="-march=athlon-xp -mtune=athlon-xp -g -pg -O2 "
bootstrap
# bootstrap-lean
Comment 1 ishikawa,chiaki 2003-09-17 18:16:10 UTC
I recall that the bootstrap 
compilation with the exactly same configuration
aroudn August 22th. So
whatever changed in between today and that date would
be the natural candidates for the cause of the bug.
Comment 2 ishikawa,chiaki 2003-09-20 16:45:01 UTC
The bootstrap succeeded WITHOUT "-pg".
So the bug is in the profile-related code.
Comment 3 Andrew Pinski 2003-09-20 16:54:06 UTC
profile_function is in the profiling code so it this definitely a regression but I have not reduced it 
yet.
Comment 4 ishikawa,chiaki 2003-09-20 18:03:43 UTC
Hi,

The way I see it, the bug seems triggered when
a function that returns a struct value is
profiled. 
(I think that 
either the register that holds the hidden pointer to the area
reserved for the return value [ passed from
the caller], or a register that holds the small struct value that
fits in a register [to be returned thus in a register] 
is forced out of the way for profiling code when
this ASM_OUTPUT_REG_PUSH is called. 

However, I wonder what happens if ASM_OUTPUT_REG_PUSH is NOT
defined. What happens on such architecture WITHOUT
ASM_OUTPUT_REG_PUSH if we specify profiling?)

The above observation might be obvious to you already, though.

BTW, a simple file below, which includes
functions that return struct values, causes stage1/cc1 to segfault
in a very similar manner as observed during bootstrap.

Looking at the generated asm output (by not adding -pg ) of this test file
might reveal some insight.

Test code: gcc-problem.c

     Attached.



segfault example:

stage1/cc1 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=4 -D__GNUC_PATCHLEVEL__=0
/home/ishikawa/BUG-DIR/GCC-BUG/gcc-problem.c -quiet -dumpbase gcc-problem.c
-auxbase gcc-problem -version  -p -o /tmp/ccrvPYue.s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory "/usr/local/lib/../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
End of search list.
GNU C version 3.4 20030919 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
/home/ishikawa/BUG-DIR/GCC-BUG/gcc-problem.c: In function `testfuncwordsimple2':

/home/ishikawa/BUG-DIR/GCC-BUG/gcc-problem.c:24: internal compiler error:
Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
ishikawa@duron$ 

ishikawa@duron$ gdb stage1/cc1
GNU gdb 5.3-debian
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...
Breakpoint 1 at 0x814f5c4: file /u2/tools/gcc-mainline-cvs/gcc/gcc/diagnostic.c,
line 593.
Breakpoint 2 at 0x8049804
Breakpoint 3 at 0x80495a4
(gdb) run -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=4 -D__GNUC_PATCHLEVEL__=0
/home/ishikawa/BUG-DIR/GCC-BUG/gcc-problem.c -quiet -dumpbase gcc-problem.c
-auxbase gcc-problem -version  -p -o /tmp/ccrvPYue.s
Starting program: /u2/tools/gcc-mainline-obj-dir/gcc/stage1/cc1 -quiet -v
-D__GNUC__=3 -D__GNUC_MINOR__=4 -D__GNUC_PATCHLEVEL__=0
/home/ishikawa/BUG-DIR/GCC-BUG/gcc-problem.c -quiet -dumpbase gcc-problem.c
-auxbase gcc-problem -version  -p -o /tmp/ccrvPYue.s
Breakpoint 2 at 0x4004b81e
Breakpoint 3 at 0x4004a8c0
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include"
ignoring nonexistent directory "/usr/local/lib/../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
End of search list.
GNU C version 3.4 20030919 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

Program received signal SIGSEGV, Segmentation fault.
0x081c6675 in profile_function (file=0x86592f0)
    at /u2/tools/gcc-mainline-cvs/gcc/gcc/final.c:1440
1440	  if (sval && GET_CODE (svrtx) == REG)
(gdb) list
1435	    }
1436	
1437	  function_section (current_function_decl);
1438	
1439	#if defined(ASM_OUTPUT_REG_PUSH)
1440	  if (sval && GET_CODE (svrtx) == REG)
1441	    ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
1442	#endif
1443	
1444	#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
(gdb) print sval
$1 = 1
(gdb) print svrtx
$2 = 0x0
(gdb) print current_function_decl
$3 = 0x40198dec
(gdb) print file
$4 = (FILE *) 0x86592f0
(gdb) quit
A debu

The file gcc-problem.c is attached as the next post.

Comment 5 ishikawa,chiaki 2003-09-20 18:06:17 UTC
Created attachment 4789 [details]
test case of functions that return struct values: cc1 segfaults with -p

This is a short test case file that contains
functions that return struct values.
They cause stage1/cc1 to segfault if we specify
profiling option.
Comment 6 Andrew Pinski 2003-09-27 04:07:33 UTC
*** Bug 12421 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2003-09-27 04:12:00 UTC
I can confirm this on the mainline (20030926).
Comment 8 Andrew Pinski 2003-10-23 20:42:54 UTC
*** Bug 12748 has been marked as a duplicate of this bug. ***
Comment 9 Volker Reichelt 2003-10-23 22:27:40 UTC
The same happens with C++ (see e.g. PR 12748).
A minimal testcase to illustrate this:

============================================
struct A {};
A foo() { return A(); }
============================================

Just compile with g++ -p to get a segfault.
Comment 10 Volker Reichelt 2003-10-23 22:35:53 UTC
Btw, according to Phil's regression hunter, the regression was
introduced between 2003-09-03-trunk (#390) and 2003-09-04-trunk (#391).
Comment 11 Volker Reichelt 2003-10-24 09:15:00 UTC
I'm afraid DJ's (really big) patch

http://gcc.gnu.org/ml/gcc-cvs/2003-09/msg00074.html

seems to be responsible for the regression.

DJ, could you please have a look?
Comment 12 Andrew Pinski 2003-10-24 22:19:25 UTC
Here for reference the patch as sent to gcc-patches: <http://gcc.gnu.org/ml/gcc-patches/2003
-09/msg00184.html>.
Comment 13 Andrew Pinski 2003-10-28 22:21:26 UTC
*** Bug 12809 has been marked as a duplicate of this bug. ***
Comment 14 DJ Delorie 2003-10-28 22:43:12 UTC
Subject: Re:  [3.4 Regression] ICE using -p with functions returning structs


> I'm afraid DJ's (really big) patch
> 
> http://gcc.gnu.org/ml/gcc-cvs/2003-09/msg00074.html
> 
> seems to be responsible for the regression.
> 
> DJ, could you please have a look?

Try this.

2003-10-28  DJ Delorie  <dj@redhat.com>

      * final.c (profile_function): Handle the case where svrtx is NULL.

Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.293
diff -p -2 -r1.293 final.c
*** final.c     18 Oct 2003 19:13:04 -0000      1.293
--- final.c     28 Oct 2003 22:41:18 -0000
*************** profile_function (FILE *file ATTRIBUTE_U
*** 1438,1442 ****
  
  #if defined(ASM_OUTPUT_REG_PUSH)
!   if (sval && GET_CODE (svrtx) == REG)
      ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
  #endif
--- 1438,1442 ----
  
  #if defined(ASM_OUTPUT_REG_PUSH)
!   if (sval && svrtx && GET_CODE (svrtx) == REG)
      ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
  #endif
*************** profile_function (FILE *file ATTRIBUTE_U
*** 1469,1473 ****
  
  #if defined(ASM_OUTPUT_REG_PUSH)
!   if (sval && GET_CODE (svrtx) == REG)
      ASM_OUTPUT_REG_POP (file, REGNO (svrtx));
  #endif
--- 1469,1473 ----
  
  #if defined(ASM_OUTPUT_REG_PUSH)
!   if (sval && svrtx && GET_CODE (svrtx) == REG)
      ASM_OUTPUT_REG_POP (file, REGNO (svrtx));
  #endif
Comment 15 Andrew Pinski 2003-10-28 22:47:42 UTC
There were two patches posted to gcc-patches today, both were the same: <http://gcc.gnu.org/
ml/gcc-patches/2003-10/msg02500.html> and <http://gcc.gnu.org/ml/gcc-patches/2003-10/
msg02503.html>.
Comment 16 Andrew Pinski 2003-10-30 06:21:01 UTC
*** Bug 12836 has been marked as a duplicate of this bug. ***
Comment 17 Andrew Pinski 2003-10-30 06:26:00 UTC
DJ, your patch is known to work, see Alan Modra's patch which really the same patch.
Comment 18 GCC Commits 2003-11-01 00:48:54 UTC
Subject: Bug 12315

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amodra@gcc.gnu.org	2003-11-01 00:48:51

Modified files:
	gcc            : ChangeLog final.c 

Log message:
	PR 12315
	* final.c (profile_function): Allow for NULL svrtx.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1630&r2=2.1631
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/final.c.diff?cvsroot=gcc&r1=1.293&r2=1.294

Comment 19 Alan Modra 2003-11-01 01:12:29 UTC
fixed