[flang] Rewrite "1*j" to "(j)", not "j", when j is a variable
authorPeter Klausler <pklausler@nvidia.com>
Wed, 21 Jun 2023 19:43:55 +0000 (12:43 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Thu, 22 Jun 2023 14:05:51 +0000 (07:05 -0700)
commitfa459d988276bb88ab577dd7a38b42a85ac8db94
tree849e8c0ea0cb9cee9af82b8a5ce36c3d8ecd0050
parent73a0ae021ec6112911b98025055b8a2e881b1376
[flang] Rewrite "1*j" to "(j)", not "j", when j is a variable

Expression folding currently unconditionally rewrites "1*j"
to "j", which is wrong when "j" is a variable, as it transforms
an expression into a variable and can lead to incorrect associations
in contexts like an actual argument or an ASSOCIATE selector.
Transform "1*j" to a parenthesized "(j)" when "j" is a variable.
Fixes LLVM bug https://github.com/llvm/llvm-project/issues/63259.

Differential Revision: https://reviews.llvm.org/D153457
flang/lib/Evaluate/fold-implementation.h
flang/test/Evaluate/rewrite04.f90 [new file with mode: 0644]