Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding arguments in clang command line

If I give clang -O2 -O3 in the same command line, in that order, is the -O3 going to override the -O2 ? Does the later argument always override?
A build script which I can't change by default adds -O2 and I can only add things after it. Is that an acceptable thing to do?

like image 470
shoosh Avatar asked Dec 15 '15 11:12

shoosh


1 Answers

Operation of the Clang driver is described in the manual page Driver Design & Internals § Driver stages. Note how you can use the -### option to get it to dump the result of each stage. This is not something you can exercise with your borken build system since the option must be listed first. But you can verify that the driver does in fact do what you hope it does:

clang -### foo.cpp -O2 -O3    # dumps yayayada "-O3" yadamore
clang -### foo.cpp -O3 -O2    # dumps yayayada "-O2" yadamore

Where “yada” is spew that I omitted since there’s too much of it. So, indeed, the last -O option you specify is the one that is effective. Which is the expected behavior for any compiler driver.

like image 177
2 revs, 2 users 71% Avatar answered Sep 27 '22 18:09

2 revs, 2 users 71%