Xcode ships LLVM 15 but Swift builds LLVM 16

The latest Xcode 15 release ships with clang 15

/Applications/Xcode_15.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --version
    Apple clang version 15.0.0 (clang-1500.0.40.1)

and LLVM 15

/Applications/Xcode_15.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-objdump --version
    Apple LLVM version 15.0.0

However, it says here that the major version of LLVM is 16, when building Swift from source.
I'm a bit confused at this point, how does this check out? Is the version of LLVM that is shipped with Xcode 15 "compatible" with the open-source Apple-LLVM 16?
If yes, is there a way to figure this out systematically? I assume the LLVM distribution shipped with Xcode to contain commits that are not open source, but I would have expected it having the same major version.

1 Like

The clang / llvm executables that ship with Xcode are separate from the versions that underly the Swift compiler itself. This is done due to the deep integration the Swift compiler has with those tools.

“Apple LLVM” always has the same major version number as the Xcode it’s packaged in; it’s unfortunate coincidence that it’s so close to the open source LLVM project version. At least when I was there (4 years ago), there was not only no standard way to map from one to the other; there was no map, since Apple LLVM branched from an arbitrary point in upstream rather than an official release.

The Clang project strongly encourages using feature tests instead of version-based tests.

7 Likes

What Jordan said. Apple clang/llvm version numbers do not map to open-source clang/llvm releases.

1 Like

Is this the case for both the clang/LLVM that ships with Xcode AND the clang/LLVM that is built during the build process of Swift? Both are "Apple clang/LLVM", but in the latter case there is no Xcode version that needs to be matched (in theory, since Swift can be used without Xcode). When you say "open-source clang/llvm", do you refer to Apple's open-source fork or the upstream clang/LLVM projects? Jordan said

“Apple LLVM” always has the same major version number as the Xcode it’s packaged in

The confusion for me is, that there are two things that can be considered "Apple LLVM", one happens to be shipped with Xcode. But does it also apply to the second, the open-source "Apple LLVM"? Does the so-called major version of open-source "Apple-LLVM" also represent an Xcode version (in this case the upcoming release, 16) or does it represent an actual major version of the upstream LLVM project? My assumption was, that it tracks a major version of upstream LLVM. Thus my reasoning went like this:

Premises:

  1. Xcode 15 ships Swift 5.9
  2. Swift 5.9 needs, according to its build process, open source Apple LLVM 16
  3. Xcode 15 ships closed source Apple LLVM 15 (where the version number is just a coincidence and can be ignored)
  4. The LLVM distribution shipped with Xcode is the one required by the Xcode Swift compiler to work (i.e. there is no other, local LLVM distribution required)

Conclusion:
Xcode 15 LLVM is closest to open source Apple LLVM 16 OR there is such a significant difference between open-source Swift and Xcode Swift, that it's possible that Xcode LLVM is closer to a different major release of open source Apple LLVM.

Do you see a flaw in this reasoning? Thank you for your answers so far.

1 Like

Sorry for being unclear; by “Apple LLVM” I meant specifically versions of LLVM/Clang that report themselves as “Apple LLVM” when you use the --version flag. “Apple Swift” is likewise a thing. Both of these are distinct from the apple/llvm-project and apple/swift repos on GitHub, which are still numbered like “public LLVM”.