flags.c: More robust flags parsing #539
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two important changes:
+ACC ... -ACC
blocks instead of only the first one.NULL
inargv[]
.These fixes were informed by the awkward bug of "passing
+RTS
or+ACC
makes the program hang indefinitely". The reason this happened was that, perhaps since recently, GHC has changed (?) approaches to parsing+RTS
arguments. I'm not sure what it did before, but at least now, it shuffles all the non-RTS arguments to the front ofargv[]
and puts aNULL
value as the first non-argument. Stale copies of other, perhaps RTS, arguments can be found after thatNULL
.What happened is that the
process_options
constructor function got called multiple times during execution (to be precise, twice); the second invocation seems to be connected toaccelerate-llvm-native
starting some threads. But the strange thing is that it only gets called once more, not numCapabillities more times.In any case, we get called multiple times, and the second time the GHC RTS had put a
NULL
inargv[]
, and we happily didn't check forNULL
and ranstrncmp()
which segfaulted. And due to some signal handler on SIGSEGV which may or may not handle that by ignoring it entirely (?), nothing happened and all froze.The direct fix for that is (2.) above, but in order to make this robust we also have to do (1.). The reason is that if a user does this:
then our first run would have parsed "abcd" as an Accelerate flag and rewritten the argument list to:
which the GHC RTS would have rewritten to:
after which the second invocation of process_options() would parse a
+ACC
block that we didn't parse before, resulting in non-idempotency. We don't want that, so we make sure to parse all+ACC
blocks the first time round.How has this been tested?
Tested this manually, locally. The first commit shows the debug prints I was using to diagnose what was happening.
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Checklist
Go over all the following points, and put an
x
in all the boxes that apply. If you're unsure about any of these, don't hesitate to ask. We're here to help!