[PATCH] D26062: Alternative solution for detecting libc++'s version.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 27 20:21:10 PDT 2016


EricWF created this revision.
EricWF added reviewers: rsmith, mclow.lists.
EricWF added subscribers: cfe-commits, rsmith.

This patch presents an alternative approach to adding a <__version> header and including it from <__config>.

Instead of using a `<__version>` header this patch adds a `__libcpp_version` *file* not intended for use as a header, and leaves `_LIBCPP_VERSION` unchanged. This prevents the additional cost of including `<__version>` from `<__config>`.  To prevent `_LIBCPP_VERSION` and `__libcpp_version` from getting out of sync we static_assert that the values match when building the library.

Additionally this patch adds a `_LIBCPP_LIBRARY_VERSION` macro for reporting the version of the dylib used. This is unrelated to @rsmith's original patch but I've been meaning to implement it for a while.


https://reviews.llvm.org/D26062

Files:
  include/__config
  include/__libcpp_version
  src/libcpp_version.cpp
  test/libcxx/version.pass.cpp


Index: test/libcxx/version.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/version.pass.cpp
@@ -0,0 +1,29 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Test the _LIBCPP_VERSION and _LIBCPP_LIBRARY_VERSION macros
+
+#include <__config>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION must be defined
+#endif
+
+#ifndef _LIBCPP_LIBRARY_VERSION
+#error _LIBCPP_LIBRARY_VERSION must be defined
+#endif
+
+#include <cassert>
+
+int main() {
+  assert(_LIBCPP_VERSION == _LIBCPP_LIBRARY_VERSION);
+  assert(std::__libcpp_library_version);
+  assert(_LIBCPP_LIBRARY_VERSION == std::__libcpp_library_version());
+}
Index: src/libcpp_version.cpp
===================================================================
--- /dev/null
+++ src/libcpp_version.cpp
@@ -0,0 +1,14 @@
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// Test that _LIBCPP_VERSION and __libcpp_version are in sync.
+// The __libcpp_version file stores only a number representing the libc++
+// version so it can be easily parsed by clang.
+static_assert(_LIBCPP_VERSION ==
+#include "__libcpp_version"
+    , "version file does not match");
+
+int __libcpp_library_version() { return _LIBCPP_VERSION; }
+
+_LIBCPP_END_NAMESPACE_STD
Index: include/__libcpp_version
===================================================================
--- /dev/null
+++ include/__libcpp_version
@@ -0,0 +1 @@
+4000
\ No newline at end of file
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -908,6 +908,13 @@
 #define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
 #endif
 
+_LIBCPP_BEGIN_NAMESPACE_STD
+_LIBCPP_FUNC_VIS _LIBCPP_WEAK int __libcpp_library_version();
+_LIBCPP_END_NAMESPACE_STD
+
+#define _LIBCPP_LIBRARY_VERSION \
+ (_VSTD::__libcpp_library_version ? _VSTD::__libcpp_library_version() : -1)
+
 #endif // __cplusplus
 
 #endif // _LIBCPP_CONFIG


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26062.76162.patch
Type: text/x-patch
Size: 2287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161028/e275f411/attachment.bin>


More information about the cfe-commits mailing list