Skip to content

Conversation

@frederik-h
Copy link
Contributor

The parsing of the --read-workers argument v is implemented like this:

unsigned threads = 0
if (!llvm::to_integer(v, threads, 0) || threads < 0) {
...

As reported by a compiler warning, the value of the "threads < 0" expession is never going to be true. It could only evaluate to true if v represents a negative number, but in this case llvm::to_integer returns false since threads is unsigned and hence the second operand of the || operator will not be evaluated.

This patch removes the useless || operand to silence compiler warnings. Since I had to first find out if --read-workers=0 is valid or not (it seems to be), I also added a test to document the valid values for the option and I adjusted the error message on invalid values to clearly state that 0 is valid.

The parsing of the --read-workers argument v is implemented like this: unsigned threads = 0 if (!llvm::to_integer(v, threads, 0) || threads < 0) { ... As reported by a compiler warning, the value of the "threads < 0" expession is never going to be true. It could only evaluate to true if v represents a negative number, but in this case llvm::to_integer returns false since threads is unsigned and hence the second operand of the || operator will not be evaluated. This patch removes the useless || operand to silence compiler warnings. Since I had to first find out if --read-workers=0 is valid or not (it seems to be), I also added a test to document the valid values for the option and I adjusted the error message on invalid values to clearly state that 0 is valid.
@frederik-h frederik-h changed the title [lld][MachO] Fix --read-workers argument parsing [lld][MachO] Silence warnings about --read-workers parsing Sep 3, 2025
@frederik-h
Copy link
Contributor Author

@johnno1962 The argument was introduced by your PR #147134, but I couldn't add you as a reviewer.

@johnno1962
Copy link
Contributor

johnno1962 commented Sep 3, 2025

Thanks for picking this up @frederik-h. If this is giving a warning the code just after it for OPT_threads_eq should be as well as I copied it. Also, while you're changing this code, perhaps the variable name should be "workers" not "threads".

@johnno1962
Copy link
Contributor

LGTM.

@frederik-h
Copy link
Contributor Author

Thanks for picking this up @frederik-h. If this is giving a warning the code just after it for OPT_threads_eq should be as well as I copied it.

No, that's fine because unsigned threads can become 0 during the parsing and that code tests for threads == 0 instead of threads < 0.

Also, while you're changing at this code, perhaps the variable name should be "workers" not "threads".

Done.

@frederik-h
Copy link
Contributor Author

@drodriguez, @johnno1962 Thank you for the review!

@frederik-h frederik-h merged commit e75f054 into llvm:main Sep 3, 2025
9 checks passed
@frederik-h frederik-h deleted the lld-read-workers-parse-warning branch September 3, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants