[cfe-dev] Macros for revision number and commit hash

Troy Johnson via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 15 20:28:32 PDT 2019


Could be useful sometimes I guess.  More generally useful though would be vendor flavors of the clang macros.  Many compilers are based on Clang but report their own version as well as the Clang version on which they are based, e.g. XYZ Clang 10 based on Clang 7.  So __vendor_major__, __vendor_minor__, etc.  Clang trunk would just default these to the clang values, but downstream compilers would make a small change.

-Troy
________________________________
From: cfe-dev <cfe-dev-bounces at lists.llvm.org> on behalf of JF Bastien via cfe-dev <cfe-dev at lists.llvm.org>
Sent: Friday, March 15, 2019 4:13:00 PM
To: cfe-dev
Cc: Jessica Paquette
Subject: [cfe-dev] Macros for revision number and commit hash

Hello macro enthusiasts!

By default, clang defines a lot of macros that allow developers to figure out things about the compiler that’s building them. I’m proposing that we add two more:

  1.  __clang_revision_number__ : an unsigned integer, representing the current branch’s revision number.
  2.  __clang_commit_hash__ : a string containing a hexadecimal hash, representing the current checkout’s hash.

These would be set by cmake when building LLVM, and make the most sense in a monorepo on git. There’s been discussion of clang revision number in the context of git migration, captured on the git migration page<https://llvm.org/docs/Proposals/GitHubMove.html#on-managing-revision-numbers-with-git>.

Here are examples of similar numbers we currently offer:

auto major     = __clang_major__;      // 7
auto minor     = __clang_minor__;      // 0
auto patch     = __clang_patchlevel__; // 0
auto version   = __clang_version__;    // "7.0.0 (tags/RELEASE_700/final 342594)”
auto VERSION   = __VERSION__;          // "4.2.1 Compatible Clang 7.0.0 (tags/RELEASE_700/final 342594)”
auto gnu_major = __GNUC__;             // 4
auto gnu_minor = __GNUC_MINOR__;       // 2
auto gnu_patch = __GNUC_PATCHLEVEL__;  // 1
auto gxx_abi   = __GXX_ABI_VERSION;    // 1002

The two new values will be generally useful to tools that automatically handle revisions. For example, we currently have bots that parse clang -v, and that output is unfortunately aimed at humans (bots aren’t human). That’s broken in the past, and having these two values would help reduce the likelihood of breakage because macros have a pretty stable format and are easy to test.

Let us know what you think!

JF




More information about the cfe-dev mailing list