This is an archive of the discontinued LLVM Phabricator instance.

[flang] Do not resolve TRIM/REPEAT length to its argument length
ClosedPublic

Authored by jeanPerier on Sep 30 2022, 9:48 AM.

Details

Summary

For TRIM and REPEAT calls, semantics was creating ProcedureDesignators
using the length parameter of the arguments. This caused bugs when
folding LEN(TRIM(char_explicit_constant_length)). The same did not
appeared in folding for REPEAT because it is rewritten at a higher
level to LEN(c)*N.

This is not only a folding issue since any place (like lowering) may
try to use the bad length parameter from the created ProcedureDesignator.

Update intrinsic resolution to not copy the length parameter for TRIM
and REPEAT.

Diff Detail

Event Timeline

jeanPerier created this revision.Sep 30 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2022, 9:48 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
jeanPerier requested review of this revision.Sep 30 2022, 9:48 AM
klausler accepted this revision.Sep 30 2022, 9:54 AM
This revision is now accepted and ready to land.Sep 30 2022, 9:54 AM

pop2 in spec2017 stopped building after this change.

I have a small reproducer. I get the following error

error: Semantic errors in my_test.f90
./my_test.f90:5:12: error: Internal error: Expression analysis failed on: Expr -> ArrayConstructor -> AcSpec
| AcValue -> Expr -> FunctionReference -> Call
| | ProcedureDesignator -> Name = 'trim'
| | ActualArgSpec
| | | ActualArg -> Expr -> Designator -> DataRef -> Name = 'n'

    call sb1((/trim(n)/))

in

program mn
  character(len=6) :: n
  n = 'hello '
  call sb1((/trim(n)/))
contains                                 
subroutine sb1(nm)
  character(*) :: nm(:)
  print *, len(nm(1))
end subroutine
end program

It was previously computing an incorrect result. So it is probably not a regression but pop2 test version used to build and run correctly before this change. Please let me know if you want me to create a github issue.