[flang] Lower optionals in GET_COMMAND_ARGUMENT and GET_ENVIRONMENT_VARIABLE
authorjeanPerier <jeanPerier@users.noreply.github.com>
Mon, 11 Apr 2022 07:33:39 +0000 (09:33 +0200)
committerJean Perier <jperier@nvidia.com>
Mon, 11 Apr 2022 07:33:49 +0000 (09:33 +0200)
commit189cb7df911b0d1aafbe60bec1a9e921827e9875
tree9e24ac0fb876d4ab0fc4ce14c477206f5497cc5b
parent9cfa899b87c583e0dcd20e4d35c8e9d337ee14f9
[flang] Lower optionals in GET_COMMAND_ARGUMENT and  GET_ENVIRONMENT_VARIABLE

Handle dynamic optional argument in GET_COMMAND_ARGUMENT and GET_ENVIRONMENT_VARIABLE
(previously compiled but caused segfaults). The previous code
handled static presence/absence aspects, but not when an absent dummy optional was
passed to one of the optional intrinsic arguments.

Simplify the runtime call lowering to simply lower the runtime call without
dealing with optionality there. This keeps the optional handling logic in
IntrinsicCall.cpp.

Note that the new code will generate some extra "if (not null addr )/then/else"
when the actual arguments are always there at runtime. That makes the implementation
a lot simpler/safer, and I think it is OK for now (I do not expect these runtime
function to be called in hot loop nests).

Differential Revision: https://reviews.llvm.org/D123388
flang/include/flang/Optimizer/Builder/FIRBuilder.h
flang/include/flang/Optimizer/Builder/Runtime/Command.h
flang/lib/Lower/IntrinsicCall.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/lib/Optimizer/Builder/Runtime/Command.cpp
flang/test/Lower/Intrinsics/get_command_argument-optional.f90 [new file with mode: 0644]
flang/test/Lower/Intrinsics/get_command_argument.f90
flang/test/Lower/Intrinsics/get_environment_variable-optional.f90 [new file with mode: 0644]
flang/test/Lower/Intrinsics/get_environment_variable.f90
flang/unittests/Optimizer/Builder/Runtime/CommandTest.cpp