This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] support hlfir.assign with unconvertable types
AbandonedPublic

Authored by tblah on Jun 12 2023, 9:41 AM.

Details

Summary

Use of the entry statement can cause different variables with different,
unconvertable types to share the same storage. A hlfir.assign for these
types cannot convert the rhs, so instead the lhs must be converted
(which is how assignments are lowered in FIR).

Example code this fixes:

complex function f1()
  logical e1
  f1 = complex(1.0, 2.0)
  entry e1()
  e1 = .false.
end function

Diff Detail

Event Timeline

tblah created this revision.Jun 12 2023, 9:41 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 12 2023, 9:41 AM
tblah requested review of this revision.Jun 12 2023, 9:41 AM
tblah edited the summary of this revision. (Show Details)Jun 12 2023, 9:41 AM
tblah updated this revision to Diff 530554.Jun 12 2023, 9:43 AM

Remove extra line in test

Thanks for working on this issue!
I think we should try to approach it the other way round: insert the fir.convert before the hlfir.declare so that the symbol get the correct type (might be required anyway to get correct debug info later). Relaxing genScalarAssignment may also silently allow some future bug to compile.

There may also be other places that do not like getting the right type than assignment but for which we lack tests.

The convert should be added on primaryFuncResultStorage before calling mapSymbolAttributes here https://github.com/llvm/llvm-project/blob/6e3a8720474528f8f752d0afbc6b8b9efab96325/flang/lib/Lower/Bridge.cpp#L3996.

tblah abandoned this revision.Jun 14 2023, 9:08 AM

Thanks for working on this issue!
I think we should try to approach it the other way round: insert the fir.convert before the hlfir.declare so that the symbol get the correct type (might be required anyway to get correct debug info later). Relaxing genScalarAssignment may also silently allow some future bug to compile.

There may also be other places that do not like getting the right type than assignment but for which we lack tests.

The convert should be added on primaryFuncResultStorage before calling mapSymbolAttributes here https://github.com/llvm/llvm-project/blob/6e3a8720474528f8f752d0afbc6b8b9efab96325/flang/lib/Lower/Bridge.cpp#L3996.

Thanks for pointing me at this, I agree this is a better solution. I've done that in https://reviews.llvm.org/D152931 and will abandon this patch.