[flang] SELECT CASE constructs with character selectors that require a temp
authorValentin Clement <clementval@gmail.com>
Thu, 30 Jun 2022 07:03:49 +0000 (09:03 +0200)
committerValentin Clement <clementval@gmail.com>
Thu, 30 Jun 2022 07:04:27 +0000 (09:04 +0200)
commit1e55ec6666fa687b1a86bdaa95ea814557855fd1
tree8d7c12df72239d18c5219735a5d1cb1dae63d7e4
parentac1bda21c9022e9dd1febf01efedfa664007fbc2
[flang] SELECT CASE constructs with character selectors that require a temp

Here is a character SELECT CASE construct that requires a temp to hold the
result of the TRIM intrinsic call:

```
module m
      character(len=6) :: s
    contains
      subroutine sc
        n = 0
        if (lge(s,'00')) then
          select case(trim(s))
          case('11')
             n = 1
          case default
             continue
          case('22')
             n = 2
          case('33')
             n = 3
          case('44':'55','66':'77','88':)
             n = 4
          end select
        end if
        print*, n
      end subroutine
    end module m
```

This SELECT CASE construct is implemented as an IF/ELSE-IF/ELSE comparison
sequence.  The temp must be retained until some comparison is successful.
At that point the temp may be freed.  Generalize statement context processing
to allow multiple finalize calls to do this, such that the program always
executes exactly one freemem call.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler, vdonaldson

Differential Revision: https://reviews.llvm.org/D128852

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
flang/include/flang/Lower/StatementContext.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/IO.cpp
flang/test/Lower/select-case-statement.f90