Details
- Reviewers
dblaikie
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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. |
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. |
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 |
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?) |
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). |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1259–1263 | it's likely not tested given the build was all green earlier. |
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!
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.