code works just fine if compiled with g++-4.2.0 --openmp but dies a horrible death if you -02
valgrind output: [EMAIL PROTECTED] ~/tmp $ valgrind ./test ==31611== Memcheck, a memory error detector. ==31611== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al. ==31611== Using LibVEX rev 1471, a library for dynamic binary translation. ==31611== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP. ==31611== Using valgrind-3.1.0, a dynamic binary instrumentation framework. ==31611== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al. ==31611== For more details, rerun with: -v ==31611== OPENMP> Thread 0 finished RHS 0 vex x86->IR: unhandled instruction bytes: 0x6C 0x3D 0x10 0x4 ==31611== Invalid read of size 1 ==31611== at 0x40FE91A: (within /home/dev2/gcc-gomp-save/gomp-gcc-build/lib/libstdc++.so.6.0.7) ==31611== by 0x8049308: main.omp_fn.0 (in /home/dev2/tmp/test) ==31611== by 0x80495C6: main (in /home/dev2/tmp/test) ==31611== Address 0x8200381 is not stack'd, malloc'd or (recently) free'd ==31611== ==31611== Process terminating with default action of signal 11 (SIGSEGV) ==31611== Access not within mapped region at address 0x8200381 ==31611== at 0x40FE91A: (within /home/dev2/gcc-gomp-save/gomp-gcc-build/lib/libstdc++.so.6.0.7) ==31611== by 0x8049308: main.omp_fn.0 (in /home/dev2/tmp/test) ==31611== by 0x80495C6: main (in /home/dev2/tmp/test) x[0]===31611== ==31611== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 25 from 1) ==31611== malloc/free: in use at exit: 16,128 bytes in 4 blocks. ==31611== malloc/free: 7 allocs, 3 frees, 16,838 bytes allocated. ==31611== For counts of detected errors, rerun with: -v ==31611== searching for pointers to 4 not-freed blocks. ==31611== checked 278,488 bytes. ==31611== ==31611== LEAK SUMMARY: ==31611== definitely lost: 0 bytes in 0 blocks. ==31611== possibly lost: 0 bytes in 0 blocks. ==31611== still reachable: 16,128 bytes in 4 blocks. ==31611== suppressed: 0 bytes in 0 blocks. ==31611== Reachable blocks (those to which a pointer was found) are not shown. ==31611== To see them, rerun with: --show-reachable=yes Segmentation fault -- Summary: [gomp] segfault in main.omp_fn.0 with -O2 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: other AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dev at stuffit dot at GCC host triplet: i686-pc-linux GCC target triplet: i686-pc-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25527