From patchwork Sun Feb 12 19:10:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 55965 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2017685wrn; Sun, 12 Feb 2023 11:11:38 -0800 (PST) X-Google-Smtp-Source: AK7set/Ckp/2xnQublkd16A0bob2RKm/xMnahz10+ig+xebrsSm+yAh4l5BKZrFadJXhlgGAOPEr X-Received: by 2002:a17:906:2a0b:b0:887:d0e6:fa24 with SMTP id j11-20020a1709062a0b00b00887d0e6fa24mr21550716eje.76.1676229098857; Sun, 12 Feb 2023 11:11:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676229098; cv=none; d=google.com; s=arc-20160816; b=maBdiURK+MNnMZQCA8p6uCVIS24kMnMeJYv3BOQxBiMrfyTvQReE+bLDng7PHuzZM6 LfT16CfdCePDy8Al2tvtN91VnHCydpMg96xGRLvphKvNRBAIhijarOoDTFLc2Dy3ataf FQa4w5R1XtQxfOpzAdMbi69sDJznSMgp6ZSHCGp7D3gWHLQCOjpdpXpa/dBL04nyQZ8X 5fi7OzDRyASvD33MEz+46RPEvhRYbPUdX8Jz817iad6rFK1yQ3k9WmYW5ztM9hJk5mcA aioeaCh0fQpkdGSOynSk0+gdKsFkbfDCoQv7BuebQzv3PEDyadNCIXurqACEq0g+ARb6 CyoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:user-agent:date:to:subject :message-id:dkim-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=J9vfQqyOEw1S2DswF4K5evZcZZG+4YB9slPa31K5i9A=; b=Nt3cV1/EImwjse5ddAh1xwi9xy9FfehplYNhdTEbyrQWfvnZRpOhq3yhHbY84NDzsO y6/RT7Fx2snz2VpTGy0dh7anIp8onRUZPd0kUDTG/R6EOMf30dxnIMWj3rjKc5tsgoOL LMCBruiSdaiC3KstSWfl/brtfDR0nBPpDWAeRoy65exjY1Fdveyme1d6RHeA2gpxDpHm t7G7CosrE9lLBfhimzNUrDyPxpt0rJdJpjOg2EGVimYBuqqnVSkfEtAA5pkWU/MpApeb xcdMnY9dM6ZhOUHh8XuQFAO19Ads5jKy5qK0zSN9E7xcSeCgp7uWSSAPKREWvIU2wKIz SQlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6HIkFYf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id et19-20020a170907295300b008af3be26c9esi9078074ejc.563.2023.02.12.11.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 11:11:38 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6HIkFYf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEB173858409 for ; Sun, 12 Feb 2023 19:11:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEB173858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676229097; bh=J9vfQqyOEw1S2DswF4K5evZcZZG+4YB9slPa31K5i9A=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Z6HIkFYfUGvNfFFv/XVBHklQOgbcODx/VIKQVh+QfqsmkZkgpJTMgeiwX+UPUZ46B T+kb8B2GU3QmQ2Vi02uiACnvYvFaIGfxqIx4xY+bU/0Eji0vDSWSsrCNrRjh+F/Z2v FTceo85N5csjCSLEDSCvdvO/FVRZT7qSjdEnslX8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id A6B643858409 for ; Sun, 12 Feb 2023 19:10:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6B643858409 Received: from [192.168.0.221] (84-115-221-28.cable.dynamic.surfer.at [84.115.221.28]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4PFH9s4B5sz1LM09 for ; Sun, 12 Feb 2023 20:10:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4PFH9s4B5sz1LM09 Message-ID: <6a1e01a49bbbefe841f59b7b2fcf0dc7fdf4ee29.camel@tugraz.at> Subject: [C PATCH] Fix ICE related to implicit access attributes for VLA arguments [PR105660] To: gcc-patches@gcc.gnu.org Date: Sun, 12 Feb 2023 20:10:40 +0100 User-Agent: Evolution 3.38.3-1+deb11u1 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.116 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Martin Uecker via Gcc-patches From: Martin Uecker Reply-To: Martin Uecker Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757653603465738484?= X-GMAIL-MSGID: =?utf-8?q?1757653603465738484?= Here is a fix for PR105660. Bootstrapped and regression tested on x86-64. Fix ICE related to implicit access attributes for VLA arguments [PR105660] When constructing the specifier string when merging an access attribute that encodes information about VLA arguments, the string was constructed in random order by iterating through a hash table. Fix this by iterating though the list of arguments. PR c/105660 gcc/Changelog * c-family/c-attribs.cc (append_access_attr): Use order of arguments when construction string. (append_access_attr_idxs): Rename and make static. * c-familty/c-warn.cc (warn_parm_array_mismatch): Add assertion. gcc/testsuite/ChangeLog: * gcc.dg/pr105660-1.c: New test. * gcc.dg/pr105660-2.c: New test. diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 4667f6de311..072cfb69147 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -4728,22 +4728,27 @@ append_access_attr (tree node[3], tree attrs, const char *attrstr, rdwr_map cur_idxs; init_attr_rdwr_indices (&cur_idxs, attrs); + tree args = TYPE_ARG_TYPES (node[0]); + int argpos = 0; std::string spec; - for (auto it = new_idxs.begin (); it != new_idxs.end (); ++it) + for (tree arg = args; arg; arg = TREE_CHAIN (arg), argpos++) { - const auto &newaxsref = *it; + const attr_access* const newa = new_idxs.get (argpos); + + if (!newa) + continue; /* The map has two equal entries for each pointer argument that has an associated size argument. Process just the entry for the former. */ - if ((unsigned)newaxsref.first != newaxsref.second.ptrarg) + if ((unsigned)argpos != newa->ptrarg) continue; - const attr_access* const cura = cur_idxs.get (newaxsref.first); + const attr_access* const cura = cur_idxs.get (argpos); if (!cura) { /* The new attribute needs to be added. */ - tree str = newaxsref.second.to_internal_string (); + tree str = newa->to_internal_string (); spec += TREE_STRING_POINTER (str); continue; } @@ -4751,7 +4756,6 @@ append_access_attr (tree node[3], tree attrs, const char *attrstr, /* The new access spec refers to an array/pointer argument for which an access spec already exists. Check and diagnose any conflicts. If no conflicts are found, merge the two. */ - const attr_access* const newa = &newaxsref.second; if (!attrstr) { @@ -4886,7 +4890,7 @@ append_access_attr (tree node[3], tree attrs, const char *attrstr, continue; /* Merge the CURA and NEWA. */ - attr_access merged = newaxsref.second; + attr_access merged = *newa; /* VLA seen in a declaration takes precedence. */ if (cura->minsize == HOST_WIDE_INT_M1U) @@ -4912,9 +4916,9 @@ append_access_attr (tree node[3], tree attrs, const char *attrstr, /* Convenience wrapper for the above. */ -tree -append_access_attr (tree node[3], tree attrs, const char *attrstr, - char code, HOST_WIDE_INT idxs[2]) +static tree +append_access_attr_idxs (tree node[3], tree attrs, const char *attrstr, + char code, HOST_WIDE_INT idxs[2]) { char attrspec[80]; int n = sprintf (attrspec, "%c%u", code, (unsigned) idxs[0] - 1); @@ -5204,7 +5208,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags, attributes specified on previous declarations of the same type and if not, concatenate the two. */ const char code = attr_access::mode_chars[mode]; - tree new_attrs = append_access_attr (node, attrs, attrstr, code, idxs); + tree new_attrs = append_access_attr_idxs (node, attrs, attrstr, code, idxs); if (!new_attrs) return NULL_TREE; @@ -5217,7 +5221,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags, { /* Repeat for the previously declared type. */ attrs = TYPE_ATTRIBUTES (TREE_TYPE (node[1])); - new_attrs = append_access_attr (node, attrs, attrstr, code, idxs); + new_attrs = append_access_attr_idxs (node, attrs, attrstr, code, idxs); if (!new_attrs) return NULL_TREE; diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 29efce3f2c0..a6fb95b1e80 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3617,6 +3617,8 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) for (tree newvbl = newa->size, curvbl = cura->size; newvbl; newvbl = TREE_CHAIN (newvbl), curvbl = TREE_CHAIN (curvbl)) { + gcc_assert (curvbl); + tree newpos = TREE_PURPOSE (newvbl); tree curpos = TREE_PURPOSE (curvbl); diff --git a/gcc/testsuite/gcc.dg/pr105660-1.c b/gcc/testsuite/gcc.dg/pr105660-1.c new file mode 100644 index 00000000000..d4454f04c43 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105660-1.c @@ -0,0 +1,13 @@ +/* PR105660 + * { dg-do compile } + * { dg-options "-std=c17" } + */ + +void gatherConservativeVars(int, int, int, int, int, int, int Hnvar, int, + int Hnyt, int Hnxyt, int, int Hstep, double[Hnyt], + double[Hnvar][Hstep][Hnxyt]); +void gatherConservativeVars(int, int, int, int, int, int, int Hnvar, int, int Hnyt, + int Hnxyt, int, int Hstep, double[Hnyt], + double[Hnvar][Hstep][Hnxyt]); + + diff --git a/gcc/testsuite/gcc.dg/pr105660-2.c b/gcc/testsuite/gcc.dg/pr105660-2.c new file mode 100644 index 00000000000..29fd82f923b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105660-2.c @@ -0,0 +1,12 @@ +/* PR105660 + * { dg-do compile } + * { dg-options "-Wall -std=c17" } + */ + + +struct bat_gen_conf_s; +void batch_generator_create2(struct bat_gen_conf_s* config, int D, int N, const long bat_dims[D][N], const long tot_dims[D][N], const long tot_strs[D][N], const _Complex float* data[D]); +void batch_generator_create2(struct bat_gen_conf_s* config, int D, int N, const long bat_dims[D][N], const long tot_dims[D][N], const long tot_strs[D][N], const _Complex float* data[D]); + + +