From patchwork Wed Jun 30 10:19:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1498864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GFJ6J08qQz9sPf for ; Wed, 30 Jun 2021 20:50:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1EC13888803 for ; Wed, 30 Jun 2021 10:19:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 38420385800B for ; Wed, 30 Jun 2021 10:19:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38420385800B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: QRYGgMIR/f+kRVGre389QG8AtUzWyU7xS5fge3VJc14QzDh4nnqLBgt5/J1oEpRke1GLWYQ6zV 2oP3sHiCSSGPpQKKVItJZMGYsIx+e+m4kjjOboy+HPiLQq8tV1WuxGfDnNofnoNiBXbmPjRG/H /9QWuRjHFRTLOGlo2ykM8DFZbR9NNrKWSfLd4A3Ueo9ho47GVTLJGPOD920g/NHvjdo6vUMvb8 va5Ny2SX5KKE027+9KRm2jSW8ZBQyx/32Z0MyzmkHCaagBhDKbXKIq0NBbSg0I/5+reV1toeoo nFk= X-IronPort-AV: E=Sophos;i="5.83,311,1616486400"; d="diff'?scan'208";a="63002061" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 30 Jun 2021 02:19:23 -0800 IronPort-SDR: pzyp3kKIVtGpXmuYmEpeZ2nHddZkK4mlN4uO3Vx58p5L416arDOnKKAkjOxXWG29FHC8n8p5NA eJw2xSwZ0/YEYumm5S1JuNEyU5LZiFs89fAkHEkaCt+SLsXW4632i5mEP2GwvbXKbSP/eMwJKT PdohN8/YIq9x4mUppy5x9lNQccMU4kpfBSTAZgixuKUlTo1kZV5GctLlvm6LGEy2n7E+11SrXZ cnbWsOgQoAI8iVTMPzdtOX8CMTQMid9tcgGddZrTN9n+cBwhOj5BFzDddIc6i+YaH+5IjqSr0w dHg= To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] gcc.c's check_offload_target_name: Fixes to inform hints Message-ID: <27b0fffb-3955-6157-a3d2-cebed062da9f@codesourcery.com> Date: Wed, 30 Jun 2021 12:19:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" As discussed at IRC: * Replace alloca by XALLOCAVEC - and while being there, do it in the whole file. * Fix splitting OFFLOAD_TARGETS at the ',' for the candidate list * More helpful inform if no targets have been configured. * For -foffload-options=, the 'target' argument may be 'nvptx,amdgcn' with len = 5. – That worked fine, except it failed to produce a hints. Now I (re)introduced target2. Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf 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, foffload-options): Add tailing '.'. gcc/common.opt | 4 ++-- gcc/gcc.c | 42 ++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index eaee74c580a..847ff98c992 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2104,11 +2104,11 @@ Support synchronous non-call exceptions. ; -foffload== is supported for backward compatibility foffload= Driver Joined MissingArgError(targets missing after %qs) --foffload= Specify offloading targets +-foffload= Specify offloading targets. foffload-options= Common Driver Joined MissingArgError(options or targets=options missing after %qs) --foffload== Specify options for the offloading targets +-foffload== 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 9baa7d67c76..f802148e567 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -2242,7 +2242,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"); @@ -3251,7 +3251,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. @@ -3430,13 +3430,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"); } @@ -3997,24 +3997,22 @@ check_offload_target_name (const char *target, ptrdiff_t len) { char *s; auto_vec 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