Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
Thanks Jonathan. Either name is perfectly fine. To clarify, this will be pushed to master and also backported to the 12-branch? Best, Marco On Tue, Jul 19, 2022 at 12:06 PM Jonathan Wakely wrote: > > On Mon, 18 Jul 2022 at 11:11, Marco Falke via Libstdc++ > wrote: > > > > (in reply to > > https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598412.html, > > adding libstdc++ to CC, with the same patch attached again) > > > > To clarify, this is not a fix for a user-facing issue of gcc or a fix > > for UB. It is just a minor UX improvement for developers that use the > > clang integer sanitizer to detect implicit int conversions. > > Thanks for the patch, I'm running tests now and will commit it once > everything passes. > > As this is an obvious, non-copyrightable fix we don't need any > paperwork of DCO sign-off for this change. Is it OK if I commit it for > the name "Marco Falke" or do you want to use the Author Name > "MacroFake" from the patch attachment? > > Thanks again. >
Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
(in reply to https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598412.html, adding libstdc++ to CC, with the same patch attached again) To clarify, this is not a fix for a user-facing issue of gcc or a fix for UB. It is just a minor UX improvement for developers that use the clang integer sanitizer to detect implicit int conversions. To reproduce: $ cat 1.cpp #include int main() { const auto a{"-1"}; unsigned b{}; std::from_chars(a, a + 2, b); } $ clang++ -fsanitize=integer -std=c++17 1.cpp -o exe && ./exe /usr/bin/../lib64/gcc/x86_64-s use-linux/12/../../../../include/c++/12/charconv:439:9: runtime error: implicit conversion from type 'int' of value -3 (32-bit, signed) to type 'unsigned char' changed the value to 253 (8-bit, unsigned) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib64/gcc/x86_64-suse-linux/12/../../../../include/c++/12/charconv:439:9 Best, Marco From 2d4e7cd1d476a065d824e11045c8dbc049d5f0a0 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Thu, 14 Jul 2022 15:26:12 +0200 Subject: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit The optimizations from commit a54137c88061c7495728fc6b8dfd0474e812b2cb introduced a clang integer sanitizer error. Fix this with an explicit static_cast, similar to the fix in commit 074436cf8cdd2a9ce75cadd36deb8301f00e55b9. libstdc++-v3/ChangeLog: * include/std/charconv (__from_chars_alnum_to_val): Replace implicit conversions from int to unsigned char with explicit casts. --- libstdc++-v3/include/std/charconv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 218813e4797..bdf23e4a5ad 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -436,7 +436,7 @@ namespace __detail __from_chars_alnum_to_val(unsigned char __c) { if _GLIBCXX17_CONSTEXPR (_DecOnly) - return __c - '0'; + return static_cast(__c - '0'); else { // This initializer is deliberately made dependent in order to work -- 2.35.3
[PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
>From 2d4e7cd1d476a065d824e11045c8dbc049d5f0a0 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Thu, 14 Jul 2022 15:26:12 +0200 Subject: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit The optimizations from commit a54137c88061c7495728fc6b8dfd0474e812b2cb introduced a clang integer sanitizer error. Fix this with an explicit static_cast, similar to the fix in commit 074436cf8cdd2a9ce75cadd36deb8301f00e55b9. libstdc++-v3/ChangeLog: * include/std/charconv (__from_chars_alnum_to_val): Replace implicit conversions from int to unsigned char with explicit casts. --- libstdc++-v3/include/std/charconv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 218813e4797..bdf23e4a5ad 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -436,7 +436,7 @@ namespace __detail __from_chars_alnum_to_val(unsigned char __c) { if _GLIBCXX17_CONSTEXPR (_DecOnly) -return __c - '0'; + return static_cast(__c - '0'); else { // This initializer is deliberately made dependent in order to work -- 2.35.3 From 2d4e7cd1d476a065d824e11045c8dbc049d5f0a0 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Thu, 14 Jul 2022 15:26:12 +0200 Subject: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit The optimizations from commit a54137c88061c7495728fc6b8dfd0474e812b2cb introduced a clang integer sanitizer error. Fix this with an explicit static_cast, similar to the fix in commit 074436cf8cdd2a9ce75cadd36deb8301f00e55b9. libstdc++-v3/ChangeLog: * include/std/charconv (__from_chars_alnum_to_val): Replace implicit conversions from int to unsigned char with explicit casts. --- libstdc++-v3/include/std/charconv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 218813e4797..bdf23e4a5ad 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -436,7 +436,7 @@ namespace __detail __from_chars_alnum_to_val(unsigned char __c) { if _GLIBCXX17_CONSTEXPR (_DecOnly) - return __c - '0'; + return static_cast(__c - '0'); else { // This initializer is deliberately made dependent in order to work -- 2.35.3