I was preparing PRs but my opinion has changed.
Though I can add the flag to all arithmetic integer operations, I’m not sure all operations should have the nsw
flag when -fno-wrapv
is enabled considering the meaning of the option. It doesn’t mean that some operations shouldn’t have the flag. I’d like to say that whether some operations have the flag wouldn’t depend on this option.
IIUC, The option is related to the language specification. According to 10.1.5.2.4 in the Fortran 2018 standard, the execution of any numeric intrinsic operation whose result is not defined by the arithmetic used by the processor is prohibited. However, some internal operations such as DO-variable increment aren’t referred to. Therefore, I suspect that the flag should be added only to such numeric intrinsic operations when the option is specified. In other words, I would implement as originally planned.
To add nsw
flag to DO-variable increment, I would introduce another new option -flang-experimental-integer-overflow
into Flang. This option doesn’t add the flag to all operations to keep consistent with -fwrapv
. (In addition, it is also because it’s hard to pass the information of options to transformation passes as I said before.)
-flang-experimental-integer-overflow
will be enabled by default and deleted in the future. On the other hand, -fno-wrapv
will also be enabled by default but -f[no-]wrapv
will remain.
I would appreciate it if you could give me some comments.