emscripten-core / emscripten-core/emscripten
Conflicting options can be processed incorrectly
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
When there are conflicting options in a command line, the last one should take effect. For example, if we give `emcc -Os -O3`, `-O3` should be accepted and not `-Os`. But we currently simply [loop through options](https://github.com/emscripten-core/emscripten/blob/126f1716359ce73ba32fe66d65f9c4a5bf5ba0e8/emcc.py#L3107) and modify settings, some of which don't get completely reverted when there is an overriding later option is encountered.
For example, when `-Os -O3` is given, even though `-Os` here is not supposed to have any effect, because we modify various `settings` as we go, they don't get reverted when we later encounter `-O3`:
https://github.com/emscripten-core/emscripten/blob/126f1716359ce73ba32fe66d65f9c4a5bf5ba0e8/emcc.py#L3160-L3161
In most cases this doesn't cause problems, but `-O?` options tend to be overlapped in many build environments, because the common build setup provides one and the local one overrides it partly, so we should make sure this works OK.
I think the solution to this is to have an API like `getLastArg` and its variants like in Clang: https://github.com/llvm/llvm-project/blob/3e49a3e89dbd44bfeb7611d76c23e137e1676abe/llvm/include/llvm/Option/ArgList.h#L254-L263
And make the loop-based current code use that API. This can be a fairly large refactoring because we need to identify all sets of options that conflict with each other. Probably what we can do easily is create the API and make use of it in a few important cases, such as `-O?` or `-g?`.
Contributor guide
Assessment
This issue has not been assessed yet.