Making -fsave-main-program a default behavior

Hello,

There are many Fortran tests (e.g. Fujitsu test suite and others) that assume that the variables in Fortran main program have implicit SAVE attribute. These tests don’t initialize such variables in some cases, relying on them having been automatically initialized to zero. With -fno-save-main-program being the default, such tests encounter undefined behavior.

Having investigated numerous failures due to the undefined behavior and having to add -fsave-main-program to all those cases, I’m wondering if it would be safer to make -fsave-main-program a default behavior in flang.

I understand that -fno-save-main-program was made default for performance reasons, but I was also told that using norecurse on QQmain program may resolve at least some of the performance issues. (Tagging @jeanPerier )

The PR to flip the behavior: [flang] Make -fsave-main-program default by eugeneepshteyn · Pull Request #137090 · llvm/llvm-project · GitHub

Please let me know your thoughs.

Thank you,
Eugene

1 Like

Thanks for writing this RFC.

Could you also share whether fsave-main-program is the default setting for all other compilers?

There was some discussion in flang does not add implicit SAVE attribute to program scope variable · Issue #133260 · llvm/llvm-project · GitHub about this topic.

You might have to change the entry related to this in llvm-project/flang/docs/Extensions.md at main · llvm/llvm-project · GitHub

We Fujitsu found that some tests in the Fujitsu Compiler Test Suite relied on Fujitsu Fortran Compiler specific flags that initialize local variables to zero. We’ll update the tests. Please see Uninitialized local variables in Fortran tests · Issue #24 · fujitsu/compiler-test-suite · GitHub for details.

Even I didn’t know that such tests exist. Thanks for making me aware of this.

Could you also share whether fsave-main-program is the default setting for all other compilers?

It turned out that most compilers don’t assume -fsave-main-program behavior, so I’m withdrawing this RFC.