[cfe-commits] r102686 - in /cfe/trunk: docs/LanguageExtensions.html lib/Frontend/InitPreprocessor.cpp test/Preprocessor/init.c
Douglas Gregor
dgregor at apple.com
Thu Apr 29 19:51:06 PDT 2010
Author: dgregor
Date: Thu Apr 29 21:51:06 2010
New Revision: 102686
URL: http://llvm.org/viewvc/llvm-project?rev=102686&view=rev
Log:
Add Clang version inspection macros. Fixes PR6681.
Modified:
cfe/trunk/docs/LanguageExtensions.html
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Preprocessor/init.c
Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=102686&r1=102685&r2=102686&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Thu Apr 29 21:51:06 2010
@@ -199,7 +199,44 @@
<h2 id="builtinmacros">Builtin Macros</h2>
<!-- ======================================================================= -->
-<p>__BASE_FILE__, __INCLUDE_LEVEL__, __TIMESTAMP__, __COUNTER__</p>
+<dl>
+ <dt><code>__BASE_FILE__</code></dt>
+ <dd>Defined to a string that contains the name of the main input
+ file passed to Clang.</dd>
+
+ <dt><code>__COUNTER__</code></dt>
+ <dd>Defined to an integer value that starts at zero and is
+ incremented each time the <code>__COUNTER__</code> macro is
+ expanded.</dd>
+
+ <dt><code>__INCLUDE_LEVEL__</code></dt>
+ <dd>Defined to an integral value that is the include depth of the
+ file currently being translated. For the main file, this value is
+ zero.</dd>
+
+ <dt><code>__TIMESTAMP__</code></dt>
+ <dd>Defined to the date and time of the last modification of the
+ current source file.</dd>
+
+ <dt><code>__clang__</code></dt>
+ <dd>Defined when compiling with Clang</dd>
+
+ <dt><code>__clang_major__</code></dt>
+ <dd>Defined to the major version number of Clang (e.g., the 2 in
+ 2.0.1).</dd>
+
+ <dt><code>__clang_minor__</code></dt>
+ <dd>Defined to the minor version number of Clang (e.g., the 0 in
+ 2.0.1).</dd>
+
+ <dt><code>__clang_patchlevel__</code></dt>
+ <dd>Defined to the patch level of Clang (e.g., the 1 in 2.0.1).</dd>
+
+ <dt><code>__clang_version__</code></dt>
+ <dd>Defined to a string that captures the Clang version, including
+ the Subversion tag or revision number, e.g., "1.5 (trunk
+ 102332)".</dd>
+</dl>
<!-- ======================================================================= -->
<h2 id="vectors">Vectors and Extended Vectors</h2>
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=102686&r1=102685&r2=102686&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Apr 29 21:51:06 2010
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Basic/Version.h"
#include "clang/Frontend/Utils.h"
#include "clang/Basic/MacroBuilder.h"
#include "clang/Basic/TargetInfo.h"
@@ -212,7 +213,20 @@
// Compiler version introspection macros.
Builder.defineMacro("__llvm__"); // LLVM Backend
Builder.defineMacro("__clang__"); // Clang Frontend
-
+#define TOSTR2(X) #X
+#define TOSTR(X) TOSTR2(X)
+ Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
+ Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
+#ifdef CLANG_VERSION_PATCHLEVEL
+ Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
+#else
+ Builder.defineMacro("__clang_patchlevel__", "0");
+#endif
+ Builder.defineMacro("__clang_version__",
+ "\"" CLANG_VERSION_STRING " ("
+ + getClangFullRepositoryVersion() + ")\"");
+#undef TOSTR
+#undef TOSTR2
// Currently claim to be compatible with GCC 4.2.1-5621.
Builder.defineMacro("__GNUC_MINOR__", "2");
Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
Modified: cfe/trunk/test/Preprocessor/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=102686&r1=102685&r2=102686&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Thu Apr 29 21:51:06 2010
@@ -48,6 +48,10 @@
// COMMON:#define __STDC__ 1
// COMMON:#define __VERSION__
// COMMON:#define __clang__ 1
+// COMMON:#define __clang_major__ 2
+// COMMON:#define __clang_minor__ 0
+// COMMON:#define __clang_patchlevel__ 0
+// COMMON:#define __clang_version__ "2.0 (trunk 102685)"
// COMMON:#define __llvm__ 1
//
//
More information about the cfe-commits
mailing list