preprocessor/6084: cpp Segmentation Fault

Gerwin, Joshua A
Fri Mar 29 12:26:00 GMT 2002

> -----Original Message-----
> From: []
> Sent: Friday, March 29, 2002 12:20 AM
> To:;;;
> Subject: Re: preprocessor/6084: cpp Segmentation Fault
> Synopsis: cpp Segmentation Fault
> State-Changed-From-To: open->feedback
> State-Changed-By: neil
> State-Changed-When: Fri Mar 29 00:20:22 2002
> State-Changed-Why:
>     Changed to category preprocessor; not a front end issue.
>     Quite a surpise to me, too.  I take pride in cpp not 
> segfaulting 8-)
>     Could you give me a testcase?  I can't reproduce it with
>     the information supplied.
>     Or, could you try 3.0.4?  There was a segfault fixed in the
>     later 3.0 cycle, triggered by a combination of command
>     line options, but I'm not sure which 3.0.x got it.
>     Judging by your command line, I suspect it is caused by
>     a certain combination of switches; can you reproduce it
>     on a simple file like #include <stdio.h> or something?
>     Alternatively, if you can't produce a simple testcase, 
> but can get it to happen on Linux, then please send me the 
> files so I can track this down, or tell me where it happens 
> when you're debugging the cpp0 binary.
>     Thanks!

Sorry about the category thing, I didn't notice a preprocessor category on
the submit form.  

The first sighting of the cpp segfault was in a troublesome build of op.c in
the vanilla perl 5.6.1 distribution from CPAN.  However, you need not go
there.  Using the same command line options, I can get it to segfault
without any source at all, simply by using ^D for stdin.  Since an empty
file may be aesthetically unsatisfying, I submit the following:

$ cat ../../../../accessories/hello.c 
#include <stdio.h>
#include <math.h>

main() {
float X;
printf("Hello, World! \n");
X = sqrt(4);
printf("the sqrt of 4 is %f \n", X);

$ /(path/to)/gcc/3.0.3-64/bin/cpp -DPERL_CORE -fno-strict-aliasing
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -mcpu=v9 -m64 -Wa,-xarch=v9 -O3
-m64 -dM -dD -dI -v ../../../../accessories/hello.c
Reading specs from
Configured with: ../gcc-3.0.3/configure --host=sparcv9-sun-solaris2
/(path/to)/gcc/3.0.3-64 --with-as=/usr/ccs/bin/as
--with-nm=/(path/to)/gcc/3.0.3-64/bin/nm --with-ld=/usr/ccs/bin/ld
Thread model: posix
gcc version 3.0.3
 /(path/to)/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0 -lang-c
-v -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__
-D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem=unix -Asystem=svr4
-D__OPTIMIZE__ -D__STDC_HOSTED__=1 -dM -dD -dI -D__SIZE_TYPE__=long unsigned
int -D__PTRDIFF_TYPE__=long int -D__WCHAR_TYPE__=int -D__WINT_TYPE__=int
-D__arch64__ -Acpu=sparc64 -Amachine=sparcv9 -D__sparcv9 -DPERL_CORE
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 ../../../../accessories/hello.c
GNU CPP version 3.0.3 (cpplib) (sparc)
ignoring nonexistent directory
#include "..." search starts here:
#include <...> search starts here:
End of search list.
cpp: Internal error: Segmentation Fault (program cpp0)
Please submit a full bug report.
See <URL:> for instructions.

A minor experiment in option removal shows that the problem is potentially
tied to the 
-dD tag.  Compare:

$ /(path/to)/gcc/3.0.3-64/bin/cpp -mcpu=v9 -m64 -Wa,-xarch=v9 -O3 -m64 -dM
-dD ../../../../accessories/hello.c
cpp: Internal error: Segmentation Fault (program cpp0)
Please submit a full bug report.
See <URL:> for instructions.

$ /usr/intel/pkgs/gcc/3.0.3-64/bin/cpp -mcpu=v9 -m64 -Wa,-xarch=v9 -O3 -m64
-dM ../../../../accessories/hello.c
#define __SIZE_TYPE__ long unsigned int
#define P_tmpdir "/var/tmp/"
#define _SSIZE_T
#define __arch64__ 1
#define __PTRDIFF_TYPE__ long int
#define _FILE_OFFSET_BITS 64
#define SEEK_SET 0
#define freopen64 freopen
#define putchar(x) putc((x), stdout)
#define ftello64 ftello
etcetera etcetera etcetera

A clue, no?

Josh Gerwin, System Programmer/Analyst
Intel Corp.
NorthWest Engineering Computing

More information about the Gcc-bugs mailing list