This is an archive of the discontinued LLVM Phabricator instance.

[flang][lowering] Handle zero extent case in LBOUND
ClosedPublic

Authored by jeanPerier on Mar 25 2022, 2:25 AM.

Details

Summary

Follow up of https://reviews.llvm.org/D121488. Ensure lower bounds
are 1 when the related dimension extent is zero. Note that lower
bounds from descriptors are now guaranteed to fulfill this property
after the runtime/codegen patches.

Also fixes explicit shape array extent lowering when instantiating
variables to deal with negative extent cases (issue found while testing
LBOUND edge case). This notably caused allocation crashes when dealing
with automatic arrays with reversed bounds or negative size
specification expression. The standard specifies that the extent of such
arrays is zero. This change has some ripple effect in the current lit
tests.

Add move two helpers as part of this change:

  • Add a helper to tell if a fir::ExtendedValue describes an assumed size array (last dimension extent is unknown to the compiler, both at compile time and runtime).
  • Move and share getIntIfConstant from Character.cpp so that it can be used elsewhere (NFC).

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 25 2022, 2:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 2:25 AM
jeanPerier requested review of this revision.Mar 25 2022, 2:25 AM
clementval accepted this revision.Mar 25 2022, 3:25 AM

LGTM

flang/lib/Lower/ConvertVariable.cpp
1093–1094

You should use brace on the if block if braces are used on the else block.

This revision is now accepted and ready to land.Mar 25 2022, 3:25 AM

Remove useless braces

jeanPerier marked an inline comment as done.Mar 25 2022, 6:36 AM
jeanPerier added inline comments.
flang/lib/Lower/ConvertVariable.cpp
1093–1094

Thanks, the brace are actually useless. I have removed them.

This revision was automatically updated to reflect the committed changes.
jeanPerier marked an inline comment as done.