From: Thomas Koenig Date: Mon, 7 Aug 2017 16:43:05 +0000 (+0000) Subject: re PR fortran/68829 (Segfaults with -Ofast due to large array on stack) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=950a884bcb5a0123791df98679a2b6367b4e2beb;p=gcc.git re PR fortran/68829 (Segfaults with -Ofast due to large array on stack) 2017-08-07 Thomas Koenig PR fortran/68829 * doc/invoke.texi: Document change in behvaior for -Ofast for Fortran. 2017-08-07 Thomas Koenig PR fortran/68829 PR fortran/81701 * options.c: Make -Ofast honor -fmax-stack-var-size. * invoke.texi: Document change. 2017-08-07 Thomas Koenig PR fortran/68829 PR fortran/81701 * gfortran.dg/o_fast_stacksize.90: New test. From-SVN: r250923 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ec8311568f3..d77a93323e1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-08-07 Thomas Koenig + + PR fortran/68829 + * doc/invoke.texi: Document change in behvaior for -Ofast for + Fortran. + 2017-08-07 Wilco Dijkstra * config/aarch64/aarch64.c (aarch64_pushwb_single_reg): diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5ae9dc4128d..5ee5b0e7b6d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7278,7 +7278,8 @@ Disregard strict standards compliance. @option{-Ofast} enables all @option{-O3} optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on @option{-ffast-math} and the Fortran-specific -@option{-fno-protect-parens} and @option{-fstack-arrays}. +@option{-fstack-arrays}, unless @option{-fmax-stack-var-size} is +specified, and @option{-fno-protect-parens}. @item -Og @opindex Og diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7c10d8c59f3..e52bd0654ae 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2017-08-07 Thomas Koenig + + PR fortran/68829 + PR fortran/81701 + * options.c: Make -Ofast honor -fmax-stack-var-size. + * invoke.texi: Document change. + 2017-08-01 Thomas König PR fortran/79312 diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 1af76aa81ec..283c8354e06 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -235,7 +235,9 @@ gfc_post_options (const char **pfilename) if (flag_protect_parens == -1) flag_protect_parens = !optimize_fast; - if (flag_stack_arrays == -1) + /* -Ofast sets implies -fstack-arrays unless an explicit size is set for + stack arrays. */ + if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2) flag_stack_arrays = optimize_fast; /* By default, disable (re)allocation during assignment for -std=f95, @@ -380,6 +382,10 @@ gfc_post_options (const char **pfilename) flag_max_stack_var_size = -1; } + /* Set flag_stack_arrays correctly. */ + if (flag_stack_arrays == -1) + flag_stack_arrays = 0; + /* Set default. */ if (flag_max_stack_var_size == -2) flag_max_stack_var_size = 32768; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 00de4c2bd8d..6a07467cecf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-08-07 Thomas Koenig + + PR fortran/68829 + PR fortran/81701 + * gfortran.dg/o_fast_stacksize.90: New test. + 2017-08-07 Wilco Dijkstra PR middle-end/46932 diff --git a/gcc/testsuite/gfortran.dg/o_fast_stacksize.f90 b/gcc/testsuite/gfortran.dg/o_fast_stacksize.f90 new file mode 100644 index 00000000000..a373d15e54e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/o_fast_stacksize.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! { dg-options "-Ofast -fmax-stack-var-size=100 -fdump-tree-original" } +MODULE foo +CONTAINS + SUBROUTINE mysum(a) + INTEGER :: a(:) + WRITE(6,*) SUM(a) + END SUBROUTINE +END MODULE foo + +USE foo +INTEGER, ALLOCATABLE :: a(:) +INTEGER, PARAMETER :: N=2**26 ! 256Mb array +ALLOCATE(a(N)) ; a=1 +CALL mysum(a*a) +END +! { dg-final { scan-tree-dump-times "__builtin_malloc" 2 "original" } }