What does the clang -cc1 option do?

12,492

Solution 1

The Clang compiler front-end has several additional Clang specific features which are not exposed through the GCC compatibility driver interface. The -cc1 argument indicates that the compiler front-end is to be used, and not the driver. The clang -cc1 functionality implements the core compiler functionality.

So, simply speaking. If you do not give -cc1 then you can expect the "look&feel" of standard GCC. That is the vast majority of compiler flags work just like you would expect them to work with GCC. If you pass the option "-cc1" then you get the Clang compiler flag set. Thus, there might be differences to GCC.

Hope that makes it a little clearer.

Solution 2

The usual compiler consists of so-called compiler driver, which knows how to execute compiler itself, assembler, linker, etc. and compiler itself which just takes the source code (sometimes already preprocessed) and emit assembler/object code.

Clang implements all these components in the single binary, the difference is just the cmdline. Here clang -cc1 invokes the compiler itself with its internal/undocumented set of options, etc.

Share:
12,492
sp497
Author by

sp497

Updated on June 05, 2022

Comments

  • sp497
    sp497 almost 2 years

    I'm a newbie in clang. I have read a paper about source to source transformation from cuda to opencl using clang compiler front end.

    Can anyone tell me why the option -cc1 is sometimes used?

  • user2023370
    user2023370 over 5 years
    Why does clang -cc1 not return immediately? I was hoping to set an alias for a clang -cc1 command with many arguments. When running it with no arguments I'd like it to return something like clang-7: error: no input files.
  • John P
    John P over 5 years
    You can test if stdin (0) is open in a terminal with [ -t 0 ], as in alias cc1='if [ -t 0 ]; then clang -cc1; else echo No; fi'. You could also look at your own arguments from a wrapper function, like alias cc1='(){ [ $# > 0 ] &&... }'; Try this, it aborts the clang call if it can't read any of the args and stdin is on the terminal. alias cc1='(){ go=false; for a do { [ -r "$a" ] || continue; go=true }; done; if ! $go && [ -t 0 ]; then echo "Sorry" 1>&2; else clang -cc1 $@; fi }'. I don't think [ -r "$a" ] is bulletproof, but it's better than just $# and that's better than nothing.
  • John P
    John P over 5 years
    If I wasn't clear, that's what I think happened - without arguments, clang falls back on reading from stdin, then "hangs" indefinitely waiting for the end-of-file. (You can send it one with ctrl+d, but you may as well ctrl+c.) The developers should already be aware of things like the TTY flag, so I have to assume they chose to leave it. This is the front end we're talking about, maybe it's designed for interaction, like Cling, their "C++ interpreter".