This is an archive of the discontinued LLVM Phabricator instance.

[flang] SELECT CASE constructs with character selectors that require a temp
ClosedPublic

Authored by clementval on Jun 29 2022, 1:18 PM.

Details

Summary

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.

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>

Diff Detail

Event Timeline

clementval created this revision.Jun 29 2022, 1:18 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 29 2022, 1:18 PM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Jun 29 2022, 1:18 PM
klausler accepted this revision.Jun 29 2022, 1:19 PM
This revision is now accepted and ready to land.Jun 29 2022, 1:19 PM
vdonaldson accepted this revision.Jun 29 2022, 1:26 PM

Thanks Valentin!

Thanks @vdonaldson @clementval for this fix. This fixes https://github.com/llvm/llvm-project/issues/56143. I believe @peixin can close D128349.

flang/lib/Lower/Bridge.cpp
1753

Compiler was flagging a warning here.

llvm-project/flang/lib/Lower/Bridge.cpp:1753:21: warning: loop variable 'attr' creates a copy from type 'const llvm::detail::result_pair<llvm::SmallVector<mlir::Attribute, 6> &>' [-Wrange-loop-construct]
    for (const auto attr : llvm::enumerate(attrList)) {
                    ^
llvm-project/flang/lib/Lower/Bridge.cpp:1753:10: note: use reference type 'const llvm::detail::result_pair<llvm::SmallVector<mlir::Attribute, 6> &> &' to prevent copying
    for (const auto attr : llvm::enumerate(attrList)) {
         ^~~~~~~~~~~~~~~~~
                    &
1 warning generated.

Thanks @vdonaldson @clementval for this fix. This fixes https://github.com/llvm/llvm-project/issues/56143. I believe @peixin can close D128349.

Warning should be fixed