From: Thomas Schwinge <thomas@codesourcery.com>
To: Jakub Jelinek <jakub@redhat.com>, <gcc-patches@gcc.gnu.org>
Cc: Tobias Burnus <tobias@codesourcery.com>
Subject: Re: [committed] openmp: Fix up strtoul and strtoull uses in libgomp
Date: Tue, 9 Nov 2021 17:06:53 +0100 [thread overview]
Message-ID: <87czn9xqhu.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <20211015144633.GF304296@tucnak>
[-- Attachment #1: Type: text/plain, Size: 3208 bytes --]
Hi!
On 2021-10-15T16:46:33+0200, Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> also discovered that the hang was a result of making wrong assumptions
> about strtoul/strtoull.
(Also 'strtol'.) ;-)
> All the uses were for portability setting
> errno = 0 before the calls and treating non-zero errno after the call
> as invalid input, but for the case where there are no valid digits at
> all strtoul may set errno to EINVAL, but doesn't have to and with
> glibc doesn't do that. So, this patch goes through all the strtoul calls
> and next to errno != 0 checks adds also endptr == startptr check.
> Haven't done it in places where we immediately reject strtoul returning 0
> the same as we reject errno != 0, because strtoul must return 0 in the
> case where it sets endptr to the start pointer. In some spots the code
> was using errno = 0; x = strtoul (p, &p, 10); if (errno) { /*invalid*/ }
> and those spots had to be changed to
> errno = 0; x = strtoul (p, &end, 10); if (errno || end == p) { /*invalid*/ }
> p = end;
ACK.
> Regtested on x86_64-linux and i686-linux, committed to trunk.
Thanks for addressing that one, too -- but evidently not properly tested
the one OpenACC change:
> (parse_gomp_openacc_dim): Likewise. Avoid strict aliasing violation.
> Make code valid C89.
(Why the C89 "re-formatting", by the way? Surely we're "violating" that
in a lot of other places?)
> --- libgomp/env.c.jj 2021-10-14 22:04:30.594333475 +0200
> +++ libgomp/env.c 2021-10-15 14:07:07.464919497 +0200
> @@ -1202,27 +1207,30 @@ parse_gomp_openacc_dim (void)
> /* The syntax is the same as for the -fopenacc-dim compilation option. */
> const char *var_name = "GOMP_OPENACC_DIM";
> const char *env_var = getenv (var_name);
> + const char *pos = env_var;
> + int i;
> +
> if (!env_var)
> return;
>
> - const char *pos = env_var;
> - int i;
> for (i = 0; *pos && i != GOMP_DIM_MAX; i++)
> {
> + char *eptr;
> + long val;
> +
> if (i && *pos++ != ':')
> break;
>
> if (*pos == ':')
> continue;
>
> - const char *eptr;
> errno = 0;
> - long val = strtol (pos, (char **)&eptr, 10);
> - if (errno || val < 0 || (unsigned)val != val)
> + val = strtol (pos, &eptr, 10);
> + if (errno || eptr != pos || val < 0 || (unsigned)val != val)
> break;
Instead of 'eptr != pos', this needs to be 'eptr == pos', like everywhere
else.
(That there are no diagnostics for malformed 'GOMP_OPENACC_DIM', is a
different topic, of course.)
>
> goacc_default_dims[i] = (int)val;
> - pos = eptr;
> + pos = (const char *) eptr;
> }
> }
Pushed to master branch commit 00c9ce13a64e324dabd8dfd236882919a3119479
"Restore 'GOMP_OPENACC_DIM' environment variable parsing", see attached.
Grüße
Thomas
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Restore-GOMP_OPENACC_DIM-environment-variable-parsin.patch --]
[-- Type: text/x-diff, Size: 1032 bytes --]
From 00c9ce13a64e324dabd8dfd236882919a3119479 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Fri, 5 Nov 2021 14:42:21 +0100
Subject: [PATCH] Restore 'GOMP_OPENACC_DIM' environment variable parsing
... that got broken by recent commit c057ed9c52c6a63a1a692268f916b1a9131cd4b7
"openmp: Fix up strtoul and strtoull uses in libgomp", resulting in spurious
FAILs for tests specifying 'dg-set-target-env-var "GOMP_OPENACC_DIM" "[...]"'.
libgomp/
* env.c (parse_gomp_openacc_dim): Restore parsing.
---
libgomp/env.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libgomp/env.c b/libgomp/env.c
index df10ff656b6..75018e8c252 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -1243,7 +1243,7 @@ parse_gomp_openacc_dim (void)
errno = 0;
val = strtol (pos, &eptr, 10);
- if (errno || eptr != pos || val < 0 || (unsigned)val != val)
+ if (errno || eptr == pos || val < 0 || (unsigned)val != val)
break;
goacc_default_dims[i] = (int)val;
--
2.33.0
prev parent reply other threads:[~2021-11-09 16:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-15 14:46 Jakub Jelinek
2021-11-09 16:06 ` Thomas Schwinge [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czn9xqhu.fsf@euler.schwinge.homeip.net \
--to=thomas@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).