[libcxx-commits] [libc] [libcxx] [llvm] [libcxx][libc] Hand in Hand PoC with from_chars (PR #91651)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 7 08:51:49 PDT 2024
================
@@ -0,0 +1,56 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
+#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
+
+#include <__assert>
+#include <__charconv/chars_format.h>
+#include <__charconv/from_chars_result.h>
+#include <__charconv/traits.h>
+#include <__config>
+#include <__system_error/errc.h>
+#include <__type_traits/enable_if.h>
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_floating_point.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 17
+
+_LIBCPP_EXPORTED_FROM_ABI from_chars_result
+__from_chars_floating_point(const char* __first, const char* __last, float& __value, chars_format __fmt);
----------------
philnik777 wrote:
Yes, something like that would be my suggestion. IIUC it would have to reload any data where it cannot prove that it doesn't alias with the arguments. So local variables should be unaffected. Anything non-trivial would be affected though I think, assuming the pointer passed to `from_chars` isn't known (which seems like a fairly common case).
Thinking about it more, maybe we actually want
```c++
[[gnu::pure]] std::tuple<float, std::errc, std::ptrdiff_t> test([[clang::noescape]] const char* first, [[clang::noescape]] const char* last, std::chars_format);
```
That would also allow the compiler to eliminate calls completely in some (granted, rare) cases. More importantly, it allows the compiler to reason more thoroughly about the function, since it now knows the function only reads memory.
I hope at some point we can give the compiler even more information (e.g. that it only reads from the argument pointers), but this is already fairly good I think.
https://github.com/llvm/llvm-project/pull/91651
More information about the libcxx-commits
mailing list