[flang-commits] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

Yi Wu via flang-commits flang-commits at lists.llvm.org
Fri Jan 5 03:10:10 PST 2024


yi-wu-arm wrote:

> Could you more easily implement SYSTEM by calling EXECUTE_COMMAND_LINE internally?

not really, I've did some experiments.
The easiest way to do it would be creating a `FORTRAN_PROCEDURE_NAME(system)` in `extension.cpp` that takes `char *arg, std::int64_t length, int returnVal`, then convert then to descriptor and call `RTNAME(ExecuteCommandLine)`.
However, for some reason the third value(returnVal) will overwrite the second value(length). It would work if the parameter input order are `int returnVal, char *arg, std::int64_t length` but that is different from gfortran syntax. 
A bold way would be using only two arguments `char *arg, int returnVal`, and the length of the command is interpreted by calling `strlen`, but that require the command to be null-terminated. using `memchr` could not be an option since it takes `length` as a parameter.

Another way to do it is to keep the lowering, and call `ExecuteCommandLine` runtime instead of creating a new one for `system`, this would definitively do the job, but I guess it won't make too much difference.

https://github.com/llvm/llvm-project/pull/74309


More information about the flang-commits mailing list