Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "clang" and "Apple clang"?

I just upgraded to OS X 10.8.2, which comes with clang. The output of clang -v is:

Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

On macports, there are several different versions of clang available (port search clang):

clang @2.9 (lang)
    C, C++, Objective C and Objective C++ compiler
clang-2.9 @2.9 (lang)
    C, C++, Objective C and Objective C++ compiler
clang-3.0 @3.0 (lang)
    C, C++, Objective C and Objective C++ compiler
clang-3.1 @3.1 (lang)
    C, C++, Objective C and Objective C++ compiler
clang-3.2 @3.2-r164372 (lang)
    C, C++, Objective C and Objective C++ compiler

Is the "Apple clang 4.1" that comes with OS X the same (nearly or exactly) as clang-3.1 from macports?

Also, what is different in 3.2 as compared to 3.1?

like image 608
Walter Avatar asked Sep 05 '25 02:09

Walter


1 Answers

Apple ships Xcode with their own version of clang. That means Apple decides how clang is built (e.g. which built settings are used, which optional features are enabled/disabled) and Apple may also patch the source code of clang to their needs prior to building it. Since clang is released under Apache 2.0 license, Apple does not have to make their changes open source or publicly available or tell anyone what they changed, how they changed it, or why they did that.

However, Apple does have an own project fork on GitHub. This is the original LLVM repo:

https://github.com/llvm/llvm-project

and this is the fork from Apple:

https://github.com/apple/llvm-project

so if they made any changes, maybe you can find them there.

The default version tells you nothing:

 # clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.4)

That's just Apple's internal version scheme, but there is a list on Wikipedia mapping those versions to LLVM release versions:

https://en.wikipedia.org/wiki/Xcode#Toolchain_versions

The way how this list is updated is by finding the appropriate release tag in the Apple fork and looking at the CMakeLists.txt. This file reveals the LLVM version:

if(NOT DEFINED LLVM_VERSION_MAJOR)
  set(LLVM_VERSION_MAJOR 16)
endif()
if(NOT DEFINED LLVM_VERSION_MINOR)
  set(LLVM_VERSION_MINOR 0)
endif()
if(NOT DEFINED LLVM_VERSION_PATCH)
  set(LLVM_VERSION_PATCH 0)
endif()

https://github.com/apple/llvm-project/blob/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-10-09-a/llvm/CMakeLists.txt

This is the current Xcode 15.1 Beta 2 tag and the CMake file reveals that is is based on LLVM 16.0.0.

like image 59
Mecki Avatar answered Sep 06 '25 15:09

Mecki