* Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
@ 2022-07-18 10:10 Marco Falke
2022-07-19 10:06 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: Marco Falke @ 2022-07-18 10:10 UTC (permalink / raw)
To: Marco Falke, libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
(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 <charconv>
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
[-- Attachment #2: 0001-libstdc-Make-__from_chars_alnum_to_val-conversion-ex.patch --]
[-- Type: text/x-patch, Size: 1244 bytes --]
From 2d4e7cd1d476a065d824e11045c8dbc049d5f0a0 Mon Sep 17 00:00:00 2001
From: MacroFake <falke.marco@gmail.com>
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<unsigned char>(__c - '0');
else
{
// This initializer is deliberately made dependent in order to work
--
2.35.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
2022-07-18 10:10 Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit Marco Falke
@ 2022-07-19 10:06 ` Jonathan Wakely
2022-07-19 10:13 ` Marco Falke
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2022-07-19 10:06 UTC (permalink / raw)
To: Marco Falke; +Cc: libstdc++, gcc-patches
On Mon, 18 Jul 2022 at 11:11, Marco Falke via Libstdc++
<libstdc++@gcc.gnu.org> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
2022-07-19 10:06 ` Jonathan Wakely
@ 2022-07-19 10:13 ` Marco Falke
2022-07-19 10:15 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: Marco Falke @ 2022-07-19 10:13 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
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 <jwakely@redhat.com> wrote:
>
> On Mon, 18 Jul 2022 at 11:11, Marco Falke via Libstdc++
> <libstdc++@gcc.gnu.org> 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.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
2022-07-19 10:13 ` Marco Falke
@ 2022-07-19 10:15 ` Jonathan Wakely
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2022-07-19 10:15 UTC (permalink / raw)
To: Marco Falke; +Cc: libstdc++, gcc-patches
On Tue, 19 Jul 2022 at 11:13, Marco Falke <falke.marco@gmail.com> wrote:
>
> Thanks Jonathan. Either name is perfectly fine.
OK, thanks.
>
> To clarify, this will be pushed to master and also backported to the 12-branch?
Yes, that's right. It will go to trunk (aka master) today and then
backported to the gcc-12 branch "soon" (whenever I do the next batch
of backports, which might be later this week).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-19 10:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 10:10 Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit Marco Falke
2022-07-19 10:06 ` Jonathan Wakely
2022-07-19 10:13 ` Marco Falke
2022-07-19 10:15 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).