This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle polymorphic value when creating temporary
ClosedPublic

Authored by clementval on Nov 29 2022, 6:56 AM.

Diff Detail

Event Timeline

clementval created this revision.Nov 29 2022, 6:56 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 29 2022, 6:56 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Nov 29 2022, 6:56 AM
clementval retitled this revision from [flang] Handle polymorphic value when creating value to [flang] Handle polymorphic value when creating temporary.Nov 29 2022, 6:59 AM

Remove debug flag

Please respond to my comment.

Aside from the one comment, all builds and tests correctly and looks good.

flang/lib/Lower/ConvertExpr.cpp
2197

This coding construct seems dangerous to me, although you're just mimicking the other cases. The function genTempExtAddr is returning a lambda where the capture is by reference. If I understand things correctly, this lambda will be evaluated after genTempExtAddr returns. The stack context at that point will not include the stack frame of genTempExtAddr. This means that any local variable declared in genTempExtAddr will not have a valid address at the point of evaluation. This section of code references the local variable loc. Thus, (again, please correct me if I have this wrong) at the time when this lambda is evaluated the reference to the variable loc will be erroneous. Furthermore, I believe that is erroneous reference will usually go undetected.

I'm guessing that there are many places in the lowering code like this.

clementval added inline comments.Nov 29 2022, 11:43 AM
flang/lib/Lower/ConvertExpr.cpp
2197

The function genTempExtAddr is returning an ExtendedValue, not a lambda. The lambda is evaluated in the match so we are fine on this side.

PeteSteinfeld accepted this revision.Nov 29 2022, 12:01 PM

Thanks, @clementval. Sorry for the false alarm.

This revision is now accepted and ready to land.Nov 29 2022, 12:01 PM

Thanks, @clementval. Sorry for the false alarm.

Thanks for the review @PeteSteinfeld

clang-format