On Fri, Mar 10, 2023 at 06:54:10PM +0100, Thomas Koenig via Gcc-patches wrote: > Hello world, here's the patch that was discussed. > > Regression-tested. OK for trunk? > > Since this appeared only in gcc13, I see no need for a backport. > I will also document this in the changes file. > > Best regards > > Thomas > > Set -frapv if -std=legacy is set.
s/frapv/fwrapv/ > Fortran legacy codes sometimes contain linear congruential > seudorandom number generators. These generators implicitly depend > on wrapping behavior on integer overflow, which is illegal Fortran, > but the best they could to at the time. > > A gcc13 change exposed this in rnflow, part of the Polyhedron > benchmark, with -O3. Rather than "regress" on such code, this patch > enables -fwrapv if -std=legacy is enabled. This allows the benchmark > to run successfully, and presumably lots of other code as well. I think it certainly shouldn't overwrite it, it can adjust the default, but if user asks for -std=legacy -fno-wrapv or -fno-wrapv -std=legacy, it should honor that. > gcc/fortran/ChangeLog: > > PR fortran/109075 > * options.cc (gfc_handle_option): If -std=legacy is set, s/ / / > also set -frwapv. s/rwapv/wrapv/ > * invoke.texi: Document the change. > --- a/gcc/fortran/options.cc > +++ b/gcc/fortran/options.cc > @@ -797,6 +797,8 @@ gfc_handle_option (size_t scode, const char *arg, > HOST_WIDE_INT value, > case OPT_std_legacy: > set_default_std_flags (); > gfc_option.warn_std = 0; > + /* -std=legacy implies -fwapv, but the user can override it. */ > + flag_wrapv = 1; > break; > > case OPT_fshort_enums: So, I think it should be done later, after option processing, say in gfc_post_options if it is possible to determine if -std=legacy has been specified (and not say -std=legacy -std=f2018 etc.), and using SET_OPTION_IF_UNSET. Jakub