public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-11] gcc.c's check_offload_target_name: Fixes to inform hints
@ 2021-07-26  9:13 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2021-07-26  9:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:29c4c74bb123c5f0b497d7fa0299fe259cb0a90a

commit 29c4c74bb123c5f0b497d7fa0299fe259cb0a90a
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Jun 30 13:17:54 2021 +0200

    gcc.c's check_offload_target_name: Fixes to inform hints
    
    gcc/ChangeLog:
    
            * gcc.c (close_at_file, execute): Replace alloca by XALLOCAVEC.
            (check_offload_target_name): Fix splitting OFFLOAD_TARGETS into
            a candidate list; better inform no offload target is configured
            and fix hint extraction when passed target is not '\0' at [len].
            * common.opt (foffload): Add tailing '.'.
            (foffload-options): Likewise; fix flag name in the help string.
    
    (cherry picked from commit a3ce7d75dd9c0308b8565669f31127436cb2ba9f)

Diff:
---
 gcc/ChangeLog.omp | 12 ++++++++++++
 gcc/common.opt    |  4 ++--
 gcc/gcc.c         | 42 ++++++++++++++++++++----------------------
 3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index c608855d3e6..41dc94dfff7 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,15 @@
+2021-07-26  Thomas Schwinge  <thomas@codesourcery.com>
+
+	Backported from master:
+	2021-06-30  Tobias Burnus  <tobias@codesourcery.com>
+
+	* gcc.c (close_at_file, execute): Replace alloca by XALLOCAVEC.
+	(check_offload_target_name): Fix splitting OFFLOAD_TARGETS into
+	a candidate list; better inform no offload target is configured
+	and fix hint extraction when passed target is not '\0' at [len].
+	* common.opt (foffload): Add tailing '.'.
+	(foffload-options): Likewise; fix flag name in the help string.
+
 2021-07-20  Andrew Stubbs  <ams@codesourcery.com>
 
 	Backport from master:
diff --git a/gcc/common.opt b/gcc/common.opt
index ccee1655837..43583eee89b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2086,11 +2086,11 @@ Support synchronous non-call exceptions.
 ; -foffload=<targets>=<options> is supported for backward compatibility
 foffload=
 Driver Joined MissingArgError(targets missing after %qs)
--foffload=<targets>	Specify offloading targets
+-foffload=<targets>	Specify offloading targets.
 
 foffload-options=
 Common Driver Joined MissingArgError(options or targets=options missing after %qs)
--foffload=<targets>=<options>	Specify options for the offloading targets
+-foffload-options=<targets>=<options>	Specify options for the offloading targets.
 
 foffload-abi=
 Common Joined RejectNegative Enum(offload_abi) Var(flag_offload_abi) Init(OFFLOAD_ABI_UNSET)
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 62ca1d59f3c..9d98f4fb012 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -2236,7 +2236,7 @@ close_at_file (void)
   if (n_args == 0)
     return;
 
-  char **argv = (char **) alloca (sizeof (char *) * (n_args + 1));
+  char **argv = XALLOCAVEC (char *, n_args + 1);
   char *temp_file = make_at_file ();
   char *at_argument = concat ("@", temp_file, NULL);
   FILE *f = fopen (temp_file, "w");
@@ -3245,7 +3245,7 @@ execute (void)
       n_commands++;
 
   /* Get storage for each command.  */
-  commands = (struct command *) alloca (n_commands * sizeof (struct command));
+  commands = XALLOCAVEC (struct command, n_commands);
 
   /* Split argbuf into its separate piped processes,
      and record info about each one.
@@ -3424,13 +3424,13 @@ execute (void)
     struct pex_time *times = NULL;
     int ret_code = 0;
 
-    statuses = (int *) alloca (n_commands * sizeof (int));
+    statuses = XALLOCAVEC (int, n_commands);
     if (!pex_get_status (pex, n_commands, statuses))
       fatal_error (input_location, "failed to get exit status: %m");
 
     if (report_times || report_times_to_file)
       {
-	times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time));
+	times = XALLOCAVEC (struct pex_time, n_commands);
 	if (!pex_get_times (pex, n_commands, times))
 	  fatal_error (input_location, "failed to get process times: %m");
       }
@@ -3991,24 +3991,22 @@ check_offload_target_name (const char *target, ptrdiff_t len)
     {
       char *s;
       auto_vec<const char*> candidates;
-      char *cand = (char *) alloca (strlen (OFFLOAD_TARGETS) + 1);
-      c = OFFLOAD_TARGETS;
-      while (c)
-	{
-	  n = strchr (c, ',');
-	  if (n == NULL)
-	    n = strchr (c, '\0');
-	  if (n - c == 0)
-	    break;
-	  strncpy (cand, c, n - c);
-	  cand[n - c] = '\0';
-	  candidates.safe_push (cand);
-	  c = *n ? n + 1 : NULL;
-	}
-      error ("GCC is not configured to support %q.*s as offload target",
-	     (int) len, target);
-      const char *hint = candidates_list_and_hint (target, s, candidates);
-      if (hint)
+      size_t olen = strlen (OFFLOAD_TARGETS) + 1;
+      char *cand = XALLOCAVEC (char, olen);
+      memcpy (cand, OFFLOAD_TARGETS, olen);
+      for (c = strtok (cand, ","); c; c = strtok (NULL, ","))
+	candidates.safe_push (c);
+
+      char *target2 = XALLOCAVEC (char, len + 1);
+      memcpy (target2, target, len);
+      target2[len] = '\0';
+
+      error ("GCC is not configured to support %qs as offload target", target2);
+
+      const char *hint = candidates_list_and_hint (target2, s, candidates);
+      if (candidates.is_empty ())
+	inform (UNKNOWN_LOCATION, "no offloading targets configured");
+      else if (hint)
 	inform (UNKNOWN_LOCATION,
 		"valid offload targets are: %s; did you mean %qs?", s, hint);
       else


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-26  9:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26  9:13 [gcc/devel/omp/gcc-11] gcc.c's check_offload_target_name: Fixes to inform hints Thomas Schwinge

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).