aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-03-31 00:53:51 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-03-31 00:53:51 +0000
commitad1a4c6e89594e704775ddb6b036ac982fd68cad (patch)
tree110ae5715868601a71bbb04ab7fe43520f37eeb0
parent3ecfa2d3218cdab5545f637a17ff46354873b63f (diff)
Change Clang's __VERSION__ to include the same basic info as in clang -v.
- Please never ever ever ever write a tool that sniffs this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128599 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Version.h5
-rw-r--r--lib/Basic/Version.cpp13
-rw-r--r--lib/Frontend/InitPreprocessor.cpp7
-rw-r--r--test/Preprocessor/init.c2
4 files changed, 25 insertions, 2 deletions
diff --git a/include/clang/Basic/Version.h b/include/clang/Basic/Version.h
index ede68ed50d..15cdf1fa02 100644
--- a/include/clang/Basic/Version.h
+++ b/include/clang/Basic/Version.h
@@ -58,6 +58,11 @@ namespace clang {
/// which includes the clang version number, the repository version,
/// and the vendor tag.
std::string getClangFullVersion();
+
+ /// \brief Retrieves a string representing the complete clang version suitable
+ /// for use in the CPP __VERSION__ macro, which includes the clang version
+ /// number, the repository version, and the vendor tag.
+ std::string getClangFullCPPVersion();
}
#endif // LLVM_CLANG_BASIC_VERSION_H
diff --git a/lib/Basic/Version.cpp b/lib/Basic/Version.cpp
index af2f848071..65cc2581da 100644
--- a/lib/Basic/Version.cpp
+++ b/lib/Basic/Version.cpp
@@ -91,4 +91,17 @@ std::string getClangFullVersion() {
return OS.str();
}
+std::string getClangFullCPPVersion() {
+ // The version string we report in __VERSION__ is just a compacted version of
+ // the one we report on the command line.
+ std::string buf;
+ llvm::raw_string_ostream OS(buf);
+#ifdef CLANG_VENDOR
+ OS << CLANG_VENDOR;
+#endif
+ OS << "Clang " CLANG_VERSION_STRING " ("
+ << getClangFullRepositoryVersion() << ')';
+ return OS.str();
+}
+
} // end namespace clang
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 3c5be253c7..928e84b185 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -247,7 +247,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
Builder.defineMacro("__GNUC__", "4");
Builder.defineMacro("__GXX_ABI_VERSION", "1002");
- Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible Clang Compiler\"");
+
+ // As sad as it is, enough software depends on the __VERSION__ for version
+ // checks that it is necessary to report 4.2.1 (the base GCC version we claim
+ // compatibility with) first.
+ Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible " +
+ llvm::Twine(getClangFullCPPVersion()) + "\"");
// Initialize language-specific preprocessor defines.
diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c
index 98b053552e..606fecce70 100644
--- a/test/Preprocessor/init.c
+++ b/test/Preprocessor/init.c
@@ -982,7 +982,7 @@
// SPARC:#define __SIZE_WIDTH__ 32
// SPARC:#define __UINTMAX_TYPE__ long long unsigned int
// SPARC:#define __USER_LABEL_PREFIX__ _
-// SPARC:#define __VERSION__ "4.2.1 Compatible Clang Compiler"
+// SPARC:#define __VERSION__ "4.2.1 Compatible
// SPARC:#define __WCHAR_MAX__ 2147483647
// SPARC:#define __WCHAR_TYPE__ int
// SPARC:#define __WCHAR_WIDTH__ 32