This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Add overload to propagate errors up to caller from ExpandResponseFiles
AbandonedPublic

Authored by oontvoo on Sep 30 2021, 9:57 PM.

Details

Reviewers
dblaikie

Diff Detail

Event Timeline

oontvoo created this revision.Sep 30 2021, 9:57 PM
oontvoo requested review of this revision.Sep 30 2021, 9:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2021, 9:57 PM
xgupta added a subscriber: xgupta.Oct 1 2021, 12:13 AM
oontvoo updated this revision to Diff 376580.Oct 1 2021, 11:15 AM

use some optional params

dblaikie added inline comments.Oct 1 2021, 11:16 AM
llvm/lib/Support/CommandLine.cpp
1194–1210

This "!FirstError / FirstError = " idiom seems like one that'd be nice to avoid. I guess it's mostly necessary because FirstError starts with success, and assigning it a new value immediately would cause an assertion about the error not being tested before being replaced.

Rather than using that idiom - perhaps the function could early return instead? This lambda could return Expected<bool>? Oh, nope, because it's used in any_of. /might/ be worth expanding that out/not using any_of to simplify the error handling in some ways I think.

1222–1224

Can this return immediately with th eerror, rather than setting the error and continuing to do more work?

1259–1263

Looks like this'll result in an assert if the function returns a non-success error, it probably needs a consumeError (or whatever it's called) in the failure case before returning false.

oontvoo added inline comments.Oct 4 2021, 12:29 PM
llvm/lib/Support/CommandLine.cpp
1194–1210

Right, I'd like to keep the first error (because usually it's the more useful than subsequent ones).

How about this - we can have it queue up all the errors and return them? (Rather than just the first one?)

1222–1224

No, because we should clean up Argv and ExpandedArgv (code below) to ensure consistency.

dblaikie added inline comments.Oct 4 2021, 12:53 PM
llvm/lib/Support/CommandLine.cpp
1194–1210

Hmm, think maybe there's some confusion - could we keep the first error and stop there, returning the error immediately, rather than tracking it through the function?

1222–1224

hmm - consistency with what? We could say that if this function produces an Error the argv should not be used - that the caller should error out immediately and not try to parse anything else from argv.

1259–1263

^ this is still pending/unaddressed

oontvoo marked 6 inline comments as done.Oct 4 2021, 5:03 PM
oontvoo added inline comments.
llvm/lib/Support/CommandLine.cpp
1222–1224

fair enough!

1259–1263

done (for real this time)

oontvoo updated this revision to Diff 377060.Oct 4 2021, 5:03 PM
oontvoo marked 2 inline comments as done.

addressed review comments

What's your motivation in making this change? Do you need this for some new or out of tree caller? Would it be possible to avoid adding this as an overload and migrate existing callers to the Error return value, rather than the bool value immediately, if there aren't too many of them? (or as follow-up commits if it's too much to do in one patch?)

llvm/lib/Support/CommandLine.cpp
1222–1224

This (changing the way argv is left on failure) only works if we actually fix the callers to do that, though - if they aren't already. Which it seems they aren't. (eg: I see one call in cl::ExpandResponseFiles that says "TODO: The error should be propagated up the stack" and another similar one in cl::ReadConfigFile.

I think it'd probably be worth doing that cleanup, if you're up for it - though it does expand the scope. If not doing that work, then yes, we probably need to preserve the argv state as it was being preserved before (at least do any tests fail/care about this? If not I might be willing to say we could break the behavior since people aren't relying on it).

1259–1263

Is this error path tested? (I would've thought if it was tested, this would've been crashing/highlighted the problem earlier - so that seems to hint that maybe this isn't tested, and should be?)

oontvoo updated this revision to Diff 377330.Oct 5 2021, 12:32 PM

updated diff

What's your motivation in making this change? Do you need this for some new or out of tree caller? Would it be possible to avoid adding this as an overload and migrate existing callers to the Error return value, rather than the bool value immediately, if there aren't too many of them? (or as follow-up commits if it's too much to do in one patch?)

The motivation was to have the error on response file not found (or not readable for whatever reasons) propagated up to caller (lld-macho in my case) so that it's clearer what the problem is. (Previously, if I ran ld64.lld @filename_with_typo.txt, it'd complain about missing arguments, whereas the real problem was the response filename being mistyped).

llvm/lib/Support/CommandLine.cpp
1222–1224

I've updated the the diff to address your original concern (most of it) wrt to the "!FirstError / FirstError = " idiom.

Ultimately, I guess I prefer to keep the current behaviour rather than overhauling it and its callers (clang seems to specifically rely on this and has a bunch of tests that failed when I tried to change this).

oontvoo added inline comments.Oct 5 2021, 12:38 PM
llvm/lib/Support/CommandLine.cpp
1259–1263

it's likely not tested given the build was all green earlier.

oontvoo abandoned this revision.Oct 6 2021, 12:44 PM

Withdrawing this . With some deliberation, I've realised this patch is actually doing the wrong thing . Specifically, the expansion here happens too early that it shouldn't know yet if it would really be an error if @foo is not a file ... it could have meant to be some variable(, eg -rpath @loader_path)

The fix I'm hoping to make can be done in lld-macho . (it also should have had a test that fails because of this patch).

Thanks for entertaining this!

Withdrawing this . With some deliberation, I've realised this patch is actually doing the wrong thing . Specifically, the expansion here happens too early that it shouldn't know yet if it would really be an error if @foo is not a file ... it could have meant to be some variable(, eg -rpath @loader_path)

The fix I'm hoping to make can be done in lld-macho . (it also should have had a test that fails because of this patch).

Thanks for entertaining this!

OK, thanks for the discussion!