[Bug c/28569] New: Segmentation fault from struct pointers

sawada at icepp dot s dot u-tokyo dot ac dot jp gcc-bugzilla@gcc.gnu.org
Wed Aug 2 10:17:00 GMT 2006

When I compile following source code with command line option -O, gcc stops due
to segmentation fault. I have attached also error message from gcc.

This problem could be fixed by initializing pointers like
   char *p = 0;
   AAA *aaa = 0;
   BBB *bbb = 0;

My system is "Linux 2.6.9-34.0.2.ELsmp #1 SMP Fri Jul 7 10:16:56 CDT 2006 i686
i686 i386 GNU/Linux"

--------source code------------
typedef struct {
   int m1;
   int m2;
} AAA;

typedef struct {
   int n1;
   int n2;
} BBB;

void function()
   char *p;
   AAA *aaa;
   BBB *bbb;

   aaa = p + bbb->n2;
   if ((p + aaa->m2) == bbb) {
      aaa->m2 = 0;

-- error message --
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2-20060722/configure --prefix=/scratch1/sawada/sw/
Thread model: posix
gcc version 4.2.0 20060722 (experimental)
 /scratch1/sawada/sw/bin/../libexec/gcc/i686-pc-linux-gnu/4.2.0/cc1 -E -quiet
-v -iprefix /scratch1/sawada/sw/bin/../lib/gcc/i686-pc-linux-gnu/4.2.0/
src/odb.c -mtune=generic -O -fpch-preprocess -o odb.i
ignoring duplicate directory
ignoring duplicate directory
#include "..." search starts here:
#include <...> search starts here:

End of search list.
-fpreprocessed odb.i -quiet -dumpbase odb.c -mtune=generic -auxbase-strip
linux/lib/odb.o -O -version -o odb.s
GNU C version 4.2.0 20060722 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 4.2.0 20060722 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: c60a7c38da40d38cd0cf294fac9048c8
src/odb.c: In function 'function':
src/odb.c:17: warning: assignment from incompatible pointer type
src/odb.c:18: warning: comparison of distinct pointer types lacks a cast
gcc4.2: Internal error: Segmentation fault (program cc1)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

           Summary: Segmentation fault from struct pointers
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sawada at icepp dot s dot u-tokyo dot ac dot jp


More information about the Gcc-bugs mailing list