This is an archive of the discontinued LLVM Phabricator instance.

[flang] Emit errors and warnings about DIM= arguments to intrinsic functions
ClosedPublic

Authored by klausler on Dec 1 2022, 3:58 PM.

Details

Summary

The semantics of many transformational intrinsic functions, especially
reductions like SUM(), are determined by the static presence or absence
of a DIM= argument. In the case of an actual DIM= argument that is
syntactically present but could be dynamically absent at execution time
(due to being OPTIONAL, POINTER, or ALLOCATABLE), f18 should emit some
kind of diagnostic message.

Other compilers either ignore this possibility or treat it as a hard
error; neither really seems correct, so let's do something more nuanced.

For cases where the dynamic absence of a value for DIM doesn't pose
as much of a risk because it lowering is going to assume that it's
equal to 1 anyway, emit only a portability warning.

For other cases where the generated code or runtime support library
will need the value of DIM= during execution, emit a warning that
the use of an OPTIONAL/POINTER/ALLOCATABLE variable or component
here is dicey and should be reconsidered.

While here, also catch bad constant DIM= values.

Diff Detail

Event Timeline

klausler created this revision.Dec 1 2022, 3:58 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
klausler requested review of this revision.Dec 1 2022, 3:58 PM
jeanPerier accepted this revision.Dec 2 2022, 12:17 AM

Please make sure you run clang-format on flang/lib/Evaluate/intrinsics.cpp. Otherwise looks good to me.

This revision is now accepted and ready to land.Dec 2 2022, 12:17 AM
This revision was landed with ongoing or failed builds.Dec 4 2022, 1:04 PM
This revision was automatically updated to reflect the committed changes.