This is an archive of the discontinued LLVM Phabricator instance.

[flang] Support for character array formats
ClosedPublic

Authored by klausler on Aug 18 2022, 11:28 AM.

Details

Summary

A character array can be used as a format in an I/O data transfer
statement, with the interpretation that its elements are concatenated
in element order to constitute the format.

Support in the runtime with an extra optional descriptor argument
to six I/O API calls; support in semantics by removing an earlier
check for a simply contiguous array presented as a format.

Some work needs to be done in lowering to pass a character array
descriptor to the I/O runtime API when present

Diff Detail

Event Timeline

klausler created this revision.Aug 18 2022, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 11:28 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
klausler requested review of this revision.Aug 18 2022, 11:28 AM
vdonaldson accepted this revision.Aug 18 2022, 11:55 AM
This revision is now accepted and ready to land.Aug 18 2022, 11:55 AM
This revision was automatically updated to reflect the committed changes.

@klausler SNAP fails with this patch. https://github.com/banach-space/llvm-project/runs/7910556327?check_suite_focus=true

/home/runner/work/llvm-project/llvm-project/build//bin/flang-new  -c time.f90
error: loc("./time.f90":19:7): 'llvm.call' op incorrect number of operands (5) for callee (expecting: 6)
error: Lowering to LLVM IR failed
Incorrect number of arguments passed to called function!
  %14 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr @_QQcl.473dced66a7e38e9ed6cb48a04ca778d, i64 42, i32 11, ptr @_QQcl.2E2F74696D652E66393000, i32 19), !dbg !15

Reproducer from SNAP

  SUBROUTINE time_summ
  CHARACTER(LEN=1) :: star='*'
  INTEGER :: i
  WRITE(*, 401) ( star, i = 1, 80 )
401 FORMAT( 10X, 'keyword Timing Summary', /, 80A, / )
  END SUBROUTINE

I see that you already mention that some work is needed in lowering. Is someone working on this part? Shall we revert this patch until then? We can have a look if no one is working on this.

Some work needs to be done in lowering to pass a character array
descriptor to the I/O runtime API when present
DavidSpickett added a subscriber: DavidSpickett.EditedAug 19 2022, 5:56 AM

Our bot also has failures and bisect pointed here. This is just one reproducer I got, so I can't be 100% they're all due to this but I see 132 instances of it in the log, and there are 173 missing exe.

https://lab.llvm.org/buildbot/#/builders/179/builds/4281

error: loc("./FM901-9bde42":47:7): 'llvm.call' op incorrect number of operands (5) for callee (expecting: 6)
error: Lowering to LLVM IR failed
flang-new: /home/david.spickett/llvm-project/llvm/lib/IR/Instructions.cpp:525: void llvm::CallInst::init(llvm::FunctionType *, llvm::Value *, ArrayRef<llvm::Value *>, ArrayRef<llvm::OperandBundleDef>, const llvm::Twine &): Assertion `(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"' failed.

Repro:

Though I think it's just https://github.com/llvm/llvm-test-suite/blob/main/Fortran/UnitTests/fcvs21_f95/FM901.f with formatting changes.

A corresponding patch to lowering is coming.