This is an archive of the discontinued LLVM Phabricator instance.

[flang][driver] Support reading response files
ClosedPublic

Authored by rovka on May 3 2022, 5:20 AM.

Details

Summary

Add support for reading response files in the flang driver. Response
files contain command line arguments and are used whenever a command
becomes longer than the shell/environment limit. Response files are
recognized via the special "@path/to/response/file.rsp" syntax, which
distinguishes them from other file inputs.

This patch hardcodes GNU tokenization, since we don't have a CL mode for
the driver. In the future we might want to add a --rsp-quoting command
line option, like clang has, to accommodate Windows platforms.

Diff Detail

Event Timeline

rovka created this revision.May 3 2022, 5:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 5:20 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
rovka requested review of this revision.May 3 2022, 5:20 AM

Thanks for working on this! I would appreciate a note about the command line semantics for response files. IIUC (based on the tests file), one just needs to prepend the filename with @, but I couldn't find any documentation.

flang/test/Driver/response-file.f90
5

What happens if you skip @? Perhaps test for that too.

flang/tools/flang-driver/driver.cpp
91

Would it make sense to move this to a dedicated function? I imagine that this might grow in the future (especially when working on Windows). No strong opinion.

rovka edited the summary of this revision. (Show Details)May 5 2022, 4:35 AM
rovka added inline comments.May 5 2022, 4:50 AM
flang/test/Driver/response-file.f90
5

We get a 'linker input unused' warning (same as clang). Not sure if that's really worth testing...

flang/tools/flang-driver/driver.cpp
91

Can do.

rovka updated this revision to Diff 427277.May 5 2022, 4:55 AM
  • Extracted helper function
  • Added a note about the @ syntax to the commit message (I hope that's what you had in mind, if not let me know!)
  • Removed the comments about writing response files. It seems we already support that thanks to the common clang infrastructure and this line. Yay \o/
  • Added a note about the @ syntax to the commit message (I hope that's what you had in mind, if not let me know!)

Your comment is perfect, thanks!

  • Removed the comments about writing response files. It seems we already support that thanks to the common clang infrastructure and this line. Yay \o/

Haha, it's been there since before flang-new existed 😂 !

flang/test/Driver/response-file.f90
5

Perhaps the actual error is not relevant, but this would be nice:

! Works fine - valid syntax
! RUN: %flang -E -cpp @%basename_t.rsp %s -o - | FileCheck %s
! Fails - invalid syntax
! RUN: not %flang -E -cpp %basename_t.rsp %s -o - | FileCheck %s
flang/tools/flang-driver/driver.cpp
91

Thanks for the update! I was thinking about something that would hide all the implementation details of dealing with response files from main, e.g.:

ProcessResponseFiles(args);

Basically, somebody scanning main does not need to know/care about response files at all, right? The most important part is that args is being updated with the contents of response files.

Perhaps I'm a bit picky, but to me response files are still something exotic and niche and hence I'm keen to make this very clear :)

This is not a blocker for me.

rovka added inline comments.May 6 2022, 2:17 AM
flang/tools/flang-driver/driver.cpp
91

You mean move the BumpPtrAllocator and StringSaver inside the helper? That would be nice, but IIUC they have to be outside of it because they're keeping the storage for whatever new args are being added (and which we use in the rest of the code below). I think I could at most move the StringSaver inside the helper and pass the Allocator in instead, but this seems like a clearer interface to me *shrug*.

rovka updated this revision to Diff 427570.May 6 2022, 2:19 AM

Add test without @.

awarzynski accepted this revision.May 16 2022, 2:07 AM

Thanks for the updates, LGTM!

This revision is now accepted and ready to land.May 16 2022, 2:07 AM
This revision was automatically updated to reflect the committed changes.