19

Note: None of the answers provided at Get Apple clang version and corresponding upstream LLVM version seems to work anymore.

The download page at http://releases.llvm.org/download.html and the Wikipedia article at https://en.wikipedia.org/wiki/Clang seems to indicate that the most recent Clang version is 6.0.0.

But on my macOS High Sierra version 10.13.3, I see this output:

$ clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ which clang
/usr/bin/clang

This does not seem right. Why is the Apple's version of Clang greater than the current version of Clang?

How do I find out which version of Clang hosted on http://releases.llvm.org/download.html does my Mac's version of Clang correspond to?

I ask this because I see http://releases.llvm.org/6.0.0/tools/clang/docs/UsersManual.html documenting a -pedantic option for the clang command line, but it is not documented in the man page of clang on my system.

$ man clang | grep pedantic
$ clang --help | grep pedantic
$
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
  • A minor search on Google got me to [this GitHub Gist page](https://gist.github.com/yamaya/2924292#gistcomment-2289472). If the linked comment is to be believed, your Mac would be using Clang version 4 or 5. – Maarten Bamelis May 17 '18 at 11:52
  • Also, the [answer on this SO question](https://stackoverflow.com/a/36000632/4841248) seems to be what you are after? It appears that Apple has redefined the version preprocessor macro to match their own versioning scheme. Some other answers on the linked question might help you in figuring out what exact LLVM version you have installed. – Maarten Bamelis May 17 '18 at 11:59
  • @MaartenBamelis The link at the SO answer you linked to has this: `clang: Apple LLVM version 9.0.0 (clang-900.0.37)`. This does not seem to provide any additional information about the versions. Do you see anything in that page that seems to provide additional information? – Lone Learner May 17 '18 at 12:10
  • 2
    There are multiple answers that suggest different approaches. They all seemed to work up to Xcode version 8.2.1; even [the Wikipedia page](https://en.wikipedia.org/wiki/Xcode#Latest_versions) fails to link later Xcode versions to a proper LLVM version. So my best guess is that there is no clear/documented relation between Apple's versions and LLVM versions from Xcode 8.3 onwards. – Maarten Bamelis May 17 '18 at 12:19
  • @MaartenBamelis So here is what I am unable to understand. According to the various sources Clang 9.1.0 that I have is based on at least Clang 4. Clang 4 has the `-pedantic` option [documented here](http://releases.llvm.org/4.0.0/tools/clang/docs/UsersManual.html). But my Clang does not seem to have `-pedantic` documented either in the `man` page or in the `--help` output. – Lone Learner May 18 '18 at 02:18
  • That is very curious... So if you say it is not documented, does that also mean it does not work when you simply use the option when using a `clang` command? – Maarten Bamelis May 18 '18 at 09:53
  • @MaartenBamelis Forgot to mention earlier. It does work. So it is in fact supported but just not documented. The way I can confirm it works is that if I use any other option such as `-foo` the compiler throws an error `unknown argument: '-foo'` but it does not throw any error for `-pedantic`. – Lone Learner May 18 '18 at 10:15
  • @LoneLearner Please just take a minute to see my answer. https://stackoverflow.com/a/70697937/10846570 Thanks! – Vittore Marcas Jan 13 '22 at 14:10

5 Answers5

6

launch terminal and enter:

clang --version

Apple clang version 11.0.0 (clang-1100.0.33.16)

jackw11111
  • 1,457
  • 1
  • 17
  • 34
Mark
  • 69
  • 1
  • 2
6

This wikipedia table maps Xcode and Apple clang versions to LLVM versions. Your clang-902.0.39.1 appears to be based on LLVM 5.0.2.

TimK
  • 4,635
  • 2
  • 27
  • 27
2

You could try using

echo | clang -dM -E - | grep __clang

and maybe that will give you more reliable numbers. Although I'm speculating since I'm not on a Mac.

Also, clang has had the -pedantic option for a long long time - many versions before 6.0. -pedantic is a GCC option and clang takes after GCC in its options.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
1

The original question asked specifically about determining the corresponding "llvm.org" Clang version for a give Apple Clang compiler, which doesn't seem to be well-addressed by the other answers. In early versions of Apple Clang, the actual base LLVM version was included in the output of the clang --version command. That hasn't been the case for years now, and many sites that list the LLVM versions don't include info past the point where Apple stopped providing it.

Apple maintains a public fork of the "llvm-project" source code on GitHub. As far as I know, this is the only reliable way to determine the base LLVM version for a given version of Xcode/Clang/Swift. Apple overrides the LLVM and Clang version numbers as part of the build process, but the original LLVM version is defined in the CMakeLists.txt file for the llvm subproject. You can use the following steps to find the version for your current Xcode:

  1. Run swift -frontend -version to get the Swift version for the installed Xcode. This seems counter-intuitive if you are trying to find the version for Clang, but Apple tags their open-source repo based on the Swift version.
  2. Open https://github.com/apple/llvm-project/blob/next/llvm/CMakeLists.txt in your web browser. This is the file that contains the LLVM version numbers, but you will first land on the current development version and not the actual version that you want.
  3. In the top left corner next to the filename, look for the drop-down button with the word "next". If you are familiar with GitHub, you know that this is the branch/tag selector.
  4. Click on the drop-down, switch to the "Tags" view, then search for swift-<version>-RELEASE, where <version> is the Swift version number from step 1. For example, Xcode 13.4 uses Swift 5.6.1 so you would search for swift-5.6.1-RELEASE. Click on the tag name to select that revision.
  5. In the CMakeLists.txt file, look for the line that sets the LLVM_VERSION_MAJOR variable. The MAJOR, MINOR and PATCH versions will give you the exact version of LLVM on which the Apple build is based. For Xcode 13.4, where Apple Clang reports a version of 13.1.6, you will see that it is based on LLVM 13.0.0.

The major version for Apple Clang is always the same as the major version of the corresponding Xcode. The fact that the major version of Apple Clang and the base LLVM happen to match in the Xcode 13.4 example is purely coincidental. Clang 13.1.6, which was first released with Xcode 13.3, is the first release in years where this has been the case, although the minor and patch versions are obviously still different.

Also be aware that Apple Clang is only based on the corresponding "llvm.org" source code. It is built from a fork that may include some Apple-specific differences, and there are also additional code changes in the proprietary Xcode release of Apple Clang that may not appear in the Apple open-source fork on GitHub.

Finally, many default values can be specified at build time and may be different between the Apple and "llvm.org" Clang compilers. For example, Apple Clang sometimes uses different default C and C++ standards when a specific standard version is not specified on the command-line. Apple Clang 13.1.6 and "llvm.org" both default to C17 for the C standard, but Apple still defaults to the original C++98 standard for C++ while "llvm.org" Clang 13 defaults to C++14.

Kenny Pitt
  • 46
  • 2
0

I am an expert on this. If you use "clang --version" to checkout the version of the clang compiler on your mac, then as you got that:

Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What you want to know that which the actual Clang version on Mac? In other words, you want to ask, which the actual Clang version for your Xcode is been used on Mac?

As your Mac terminal output,(The output tells you things about your Xcode on your mac) the first line "Apple LLVM version 9.1.0 (clang-902.0.39.1)" means: your installed Xcode version was 9.3 or 9.3.1, including the default installed Clang version 9.1.0(This Clang version Identifier wasclang-902.0.39.1). the second and third line do no matter with your Clang Version. the fourth line "InstalledDir: /Library/Developer/CommandLineTools/usr/bin"means:

Where is your now using Clang locations. Or, if you want to know which clang version are your Xcode(mac) using? you need to go that directory /Library/Developer/CommandLineTools/usr/bin. Just use this command to checkout which clang version your Mac(==Xcode) are using now:

cd /Library/Developer/CommandLineTools/usr/lib/clang/ && ls

That may show like this: 9.0.0 or 9.1.0 or 10.0.0. As this may show, The Clang version of your Xcode Now may use 9.0.0, or 9.0.1 or 10.0.0. But why your now using Clang version is different from the default installed Clang version of Xcode including? Or, why there is another Clang version out of the default including Clang version of Xcode? Or, Xcode comes with Clang, why there is another version Clang?

As I know, the newable version of Xcodes are including the Command Line Tools. Or, the new version of Xcode comes with Command Line Tools; or, If you use Xcode, the Command Line Tools are also embedded within the Xcode IDE. And the Command Line Tool are including many useful tools, such as the Apple LLVM compiler(LLVM-Clang), linker, and Make.

Also, Why you have a Command Line Tools of Xcode and another separated Command-Line Tools. Maybe you install a separated Command Line Tools after installing Xcode! And, you may select the separated Command-Line Tools via using "xcode-select --switch <path>" to replace the default Command Line Tools of Xcode according to the old blog's guidance. Just like this image(from Chinese Website juejing) Your Mac Chosed embeded Xcode command-line tools

As I see, The Xcode.app was stored in /Applications/Xcode.app/Contents/Developer. The separated Command Line Tools was stored in /Library/Developer/CommandLineTools. Just like this image(from Chinese Blog Website juejin): separated command-line tools VS embeded Xcode command-line tools So, when you use "clang --version" to check out the clang version of your Mac you are using, that shows:

Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

So, if you are using the default Xcode of command-line Tools, what would that "clang --version" output? Here comes the using default Xcode of command-line Tools:

Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

All in all, if you have more than one xcode installed on mac or more than one separated command-line tools, you will have more than one command-line tools; Just like the image(from Chinese Website Blog juejin) shows: command-line-tools(macOS10.14SDK) VS command-line-tools(macOS10.15SDK) Others, the connection of Xcode and command-line tools just like this image(from Chinese Website juejin)

Xcode connect with command-line tools

Also, you will have more than one clang to choose from using.

Last, what i want to say is, which clang version are your mac using, that depends the directory of command-line tools's chosed InstalledDir. If your mac use the default embeded Xcode command-line tools, then, that "Apple LLVM version 9.1.0 (clang-902.0.39.1)" shows your using Clang 9.1.0 with it's Identifier clang-902.0.39.1, your using Clang installed dirctory was in

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

If your mac use separated command-line tools, then, that "Apple LLVM version 9.1.0 (clang-902.0.39.1)" ONLY express your installed Xcode 9.3/9.3.1 with embedded command-line tools(Clang 9.1.0) , Your mac Now used command-line tools was from Xcode. And, that "InstalledDir: /Library/Developer/CommandLineTools/usr/bin" shows where Now your Mac using command-line tools(Clang compiler) was in or where Now your Mac using Clang compiler was in.

Last Last Last, Your macOS High Sierra version 10.13.3 could install Xcode version up to Xcode 10.1, and Clang version up to Clang 10.0.0. As your "clang --version" shows, you are not using the embedded Xcode command-line tools(Clang). Now You are using the separated (command-line tools)/Clang, enter Your InstalledDir show directory "/Library/Developer/CommandLineTools/usr/bin" to checkout Now Your Mac using version. Just using this command to checkout what the version of Clang you are using:

cd /Library/Developer/CommandLineTools/usr/lib/clang/ && ls 

(Infer from the command-line tools downloadable on your computer's current system 10.13.3) Take my macOS 10.12 for example, my Xcode could up to Xcode9.2, and Clang could up to Clang9.0.0, Because I have installed separated command-line tools with Clang 9.0.0, My VSCode C/C++ compiler just use Clang9.0.0 via the separated command-line tools, My Xcode C/C++ compiler just uses Clang8.1.0 via the embedded Xcode command-line tools.

Vittore Marcas
  • 1,007
  • 8
  • 11
  • This answer takes me eight hours. But I think, Leave enough blank lines between each sentence to make it clearer. If I sacrifice the necessary blank lines, then I can edit it again. – Vittore Marcas Jan 13 '22 at 14:50