How to detect LLVM and its version through #define directives? How to detect LLVM and its version through #define directives? c c

How to detect LLVM and its version through #define directives?


The __llvm__ and __clang__ macros are the official way to check for an LLVM compiler (llvm-gcc or clang) or clang, respectively.

__has_feature and __has_builtin are the recommended way of checking for optional compiler features when using clang, they are documented here.

Note that you can find a list of the builtin compiler macros for gcc, llvm-gcc, and clang using:

echo | clang -dM -E -

This preprocesses an empty string and spits out all macros defined by the compiler.


I cannot find an answer here, only links to answers, so for completeness, here is the answer:

__clang__             // set to 1 if compiler is clang__clang_major__       // integer: major marketing version number of clang__clang_minor__       // integer: minor marketing version number of clang__clang_patchlevel__  // integer: marketing patch level of clang__clang_version__     // string: full version number

I get currently:

__clang__=1__clang_major__=3__clang_minor__=2__clang_patchlevel__=0__clang_version__="3.2 (tags/RELEASE_32/final)"


For clang, you shouldn't test its version number, you should check for features you want with feature checking macros.