public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration
@ 2015-06-19 17:55 gunney1 at llnl dot gov
  2015-06-19 19:44 ` [Bug c++/66603] " glisse at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gunney1 at llnl dot gov @ 2015-06-19 17:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66603

            Bug ID: 66603
           Summary: using std::cout causes segfault with unrelated array
                    declaration
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gunney1 at llnl dot gov
  Target Milestone: ---

Created attachment 35816
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35816&action=edit
.ii file from g++ command

Replicator:

#include <iostream>
int main () {
   std::cout << 1;
   int a[4000000];
   // int *a = new int[8000000]; delete [] a;
}

this program segfaults with g++ (4.5.0, 4.6.1, 4.8.4, 5.1.0) but not with icpc.
Oddly, commenting out the stream insert fixes the segfault.
Replacing array with new/delete also works.
New/delete allocates more data, so memory is not the issue here.

> g++ -v -save-temps P1.C
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.1.0/configure
--prefix=/home/gunney1/opt/gcc/5.1.0/installed
Thread model: posix
gcc version 5.1.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'

/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/cc1plus
-E -quiet -v -D_GNU_SOURCE P1.C -mtune=generic -march=x86-64 -fpch-preprocess
-o P1.ii
ignoring nonexistent directory
"/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../include/c++/5.1.0

/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../include/c++/5.1.0/x86_64-unknown-linux-gnu

/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../include/c++/5.1.0/backward

/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/include
 /usr/local/include
 /home/gunney1/opt/gcc/5.1.0/installed/include

/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'

/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/cc1plus
-fpreprocessed P1.ii -quiet -dumpbase P1.C -mtune=generic -march=x86-64
-auxbase P1 -version -o P1.s
GNU C++ (GCC) version 5.1.0 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 5.1.0, GMP version 4.3.1, MPFR version 2.4.1,
MPC version 0.8
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 5.1.0 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 5.1.0, GMP version 4.3.1, MPFR version 2.4.1,
MPC version 0.8
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a812ed01a29b2a8404e588f77961fe34
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 as -v --64 -o P1.o P1.s
GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version
version 2.20.51.0.2-5.42.el6 20100205
COMPILER_PATH=/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/:/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/:/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/:/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/:/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/:/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'

/home/gunney1/opt/gcc/5.1.0/installed/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/collect2
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/crtbegin.o
-L/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0
-L/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../..
P1.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/gunney1/opt/gcc/5.1.0/installed/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/crtend.o
/usr/lib/../lib64/crtn.o
191051 gunney1-lx~/bugrep/gcc-cout-segfault> ./a.out
Segmentation fault (core dumped)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/66603] using std::cout causes segfault with unrelated array declaration
  2015-06-19 17:55 [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration gunney1 at llnl dot gov
@ 2015-06-19 19:44 ` glisse at gcc dot gnu.org
  2015-06-19 19:59 ` gunney1 at llnl dot gov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-06-19 19:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66603

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
That looks like a good old stack overflow, why do you think there is a bug?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/66603] using std::cout causes segfault with unrelated array declaration
  2015-06-19 17:55 [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration gunney1 at llnl dot gov
  2015-06-19 19:44 ` [Bug c++/66603] " glisse at gcc dot gnu.org
@ 2015-06-19 19:59 ` gunney1 at llnl dot gov
  2015-06-19 20:10 ` glisse at gcc dot gnu.org
  2015-06-19 20:16 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gunney1 at llnl dot gov @ 2015-06-19 19:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66603

--- Comment #3 from gunney1 at llnl dot gov ---
Because of the effects of the stream insertion.  But maybe I don't understand
very well their relationship.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/66603] using std::cout causes segfault with unrelated array declaration
  2015-06-19 17:55 [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration gunney1 at llnl dot gov
  2015-06-19 19:44 ` [Bug c++/66603] " glisse at gcc dot gnu.org
  2015-06-19 19:59 ` gunney1 at llnl dot gov
@ 2015-06-19 20:10 ` glisse at gcc dot gnu.org
  2015-06-19 20:16 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-06-19 20:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66603

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to gunney1 from comment #3)
> Because of the effects of the stream insertion.  But maybe I don't
> understand very well their relationship.

First, I guess it does not crash with icpc because icpc optimizes by default.
g++ -O also optimizes 'a' away.

Simply mentioning a huge stack array does not produce the crash. The issue is
when something (anything, in this case placing the arguments for the function
call) tries to use the stack after that array (outside of the stack, since the
array is so large).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/66603] using std::cout causes segfault with unrelated array declaration
  2015-06-19 17:55 [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration gunney1 at llnl dot gov
                   ` (2 preceding siblings ...)
  2015-06-19 20:10 ` glisse at gcc dot gnu.org
@ 2015-06-19 20:16 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-06-19 20:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66603

--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
Another detail that might confuse you: if you write
in n=4000000;
int a[n];

it will probably not crash. The reason is that variables like 'int a[4000000]'
exist for the whole length of the function, the memory for them is reserved at
function entry, so the stream operation happens after the memory was reserved.
On the other hand, a dynamic allocation (VLA) happens at the point where it is
requested, i.e. after the stream op, and there is no operation afterwards to
use the stack and crash the program.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-19 20:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19 17:55 [Bug c++/66603] New: using std::cout causes segfault with unrelated array declaration gunney1 at llnl dot gov
2015-06-19 19:44 ` [Bug c++/66603] " glisse at gcc dot gnu.org
2015-06-19 19:59 ` gunney1 at llnl dot gov
2015-06-19 20:10 ` glisse at gcc dot gnu.org
2015-06-19 20:16 ` glisse at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).