E.g., what happens when you type clang -O3 -O0?
Is the behavior the same as in gcc? I.e., all but the last optimization flags are ignored (described here and here)?
I looked up in the manual page for clang but couldn't find an explanation in the optimization flag section.
Is it undefined behaviour?
Though a test case does not provide a definitive proof of uniform behavior throughout, it may hint on one or another direction, from what I was able to observe in test cases for Clang in several versions both with C and C++ code, it appears that, as in GCC, the previous conflicting flags are ignored and the last one stands. I did look into the Clang documentation and it appears no mention is made about this situation.
Sample C program with Clang 11.0.1
The assumption may be that this will not be an issue and that obviously the last flag is the one that stands. One might argue that is not so obvious, for example, an argument can be made that the higher optimization level should stand.
As to why it was not documented, one can only speculate, maybe lack of awareness of the situation lead to it. The fact is that this should at least, as in GCC, be documented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With