[cfe-commits] r128599 - in /cfe/trunk: include/clang/Basic/Version.h lib/Basic/Version.cpp lib/Frontend/InitPreprocessor.cpp test/Preprocessor/init.c

Daniel Dunbar daniel at zuster.org
Wed Mar 30 17:53:51 PDT 2011


Author: ddunbar
Date: Wed Mar 30 19:53:51 2011
New Revision: 128599

URL: http://llvm.org/viewvc/llvm-project?rev=128599&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/Version.h
    cfe/trunk/lib/Basic/Version.cpp
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
    cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/include/clang/Basic/Version.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Version.h?rev=128599&r1=128598&r2=128599&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Version.h (original)
+++ cfe/trunk/include/clang/Basic/Version.h Wed Mar 30 19:53:51 2011
@@ -58,6 +58,11 @@
   ///   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

Modified: cfe/trunk/lib/Basic/Version.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Version.cpp?rev=128599&r1=128598&r2=128599&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Version.cpp (original)
+++ cfe/trunk/lib/Basic/Version.cpp Wed Mar 30 19:53:51 2011
@@ -91,4 +91,17 @@
   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

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=128599&r1=128598&r2=128599&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Mar 30 19:53:51 2011
@@ -247,7 +247,12 @@
   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.
 

Modified: cfe/trunk/test/Preprocessor/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=128599&r1=128598&r2=128599&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Wed Mar 30 19:53:51 2011
@@ -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





More information about the cfe-commits mailing list