This is an archive of the discontinued LLVM Phabricator instance.

[flang] Implement GET_ENVIRONMENT_VARIABLE(LENGTH)
ClosedPublic

Authored by rovka on Oct 8 2021, 2:51 AM.

Details

Summary

Search for the environment variable in the envp string passed to
ProgramStart. This will only work if ProgramStart was actually called,
i.e. if the main program is Fortran.

Diff Detail

Event Timeline

rovka created this revision.Oct 8 2021, 2:51 AM
rovka requested review of this revision.Oct 8 2021, 2:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 8 2021, 2:51 AM
klausler added inline comments.Oct 8 2021, 10:23 AM
flang/runtime/command.cpp
86

This will fail badly when the entire name is blank.

flang/runtime/environment.cpp
74

This won't work at all if ProgramStart is never called, and it won't be called when the main program is not Fortran. You need to test envp for validity and deal with the case of it being null.

rovka updated this revision to Diff 378991.Oct 12 2021, 5:54 AM
rovka edited the summary of this revision. (Show Details)

Fixed. I'm working on a follow-up patch to call std::getenv if we don't find anything in envp. Does that sound good?

Please implement a getenv path for the case without envp, or put a big TODO comment about it in the place where it needs to go. It might be easiest to simply implement it.

klausler accepted this revision.Oct 12 2021, 9:28 AM
This revision is now accepted and ready to land.Oct 12 2021, 9:28 AM
This revision was automatically updated to reflect the committed changes.