From patchwork Wed Feb 8 12:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 54420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3413595wrn; Wed, 8 Feb 2023 04:03:26 -0800 (PST) X-Google-Smtp-Source: AK7set/uhOnkrIsJ54TsKuSQxnkA1p2M/NalxZfNA09SJyI40pzzTASaaRfwzNR9Ix/2l1d9tRJh X-Received: by 2002:a17:907:86a7:b0:8aa:5c70:1024 with SMTP id qa39-20020a17090786a700b008aa5c701024mr7215781ejc.44.1675857806522; Wed, 08 Feb 2023 04:03:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675857806; cv=none; d=google.com; s=arc-20160816; b=bCojmqmEi0wrFwyX5snSeXzlQzeSVX9AYNBdk0AXYxzgQCWlfN1dGcBNj8EBCtj6TX DnIIXENrLY0BMiRcOB8fgnAojGpX5Ximeioks1EikJgR0Kyl27fOSTXxicX0hMOok9XV bKsoE52cWAX8kswwMFuM3MRy/1HUMFpP37sQTbDM4DigzBSpwhZSEPRgFGg7OJ6xffxA zh+iwXDNyyewnEBaHYw/X6yfBuKh1dJimhf/+Kc0kN0uffkE0u6wCI/Qk8f9cJEgkUwS eK4P4yFjI6UDMri6iBOpY4MCNvCSKsuHXUwtwVB4kq5gcZTmXv09u3DIyU5s63RX2dBg +UJw== 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=BI+erHawwlSSRrVL9t1mvQH1xDTUL4D9Xi7H6Inm678=; b=u6iPZyNd27kdX75ndp+krWHNUp+BcoE+F+oJzuUA18+fqJ1OHAgVfdCGn6Nft6nI/e 90rL7lF7CT5Heku4PsUvD0yo7MzxtQrRSMsMdT3UVlTX38S1JTL9hBL2i50klE+e7dQk YPn+mkmcaps4uzZaqRBlv+pJc/WVq+SHuspV+CSAggliET88dAyHHnOl2MObQxmFXAct BJwK3uAQ9C3klnfEu19TNHT3c3sHMGRpNJB2DT3JozO50tC82aJVzRemE7XRJ3VnXVmW guYDgxGCz/pXxSYAtD7hGD3qOthRuabrD5aJOBhwOTpROMaSilm3Ts69ULuTP9/hqGBz vefQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MMpmIx76; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g16-20020a1709065d1000b0088364d70fbcsi1398960ejt.960.2023.02.08.04.03.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 04:03:26 -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=MMpmIx76; 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 9447A3858C3A for ; Wed, 8 Feb 2023 12:03:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9447A3858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675857805; bh=BI+erHawwlSSRrVL9t1mvQH1xDTUL4D9Xi7H6Inm678=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MMpmIx762GlNLaUqhj3GwJkK3gWPkycQ+c5KMQYg5kn9dvqVqB0jmber0a81jbaQa NEKpY4TqkyOP7M5XIEbxpNoILrvIO1QKhsdynn60/bC7KBi9F5drDXB1bNSbO06QXD CYUZlPhKap3xgV3Y7DZ7H789EM7BkERlxaO3gc2U= 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 5EEB13858D39 for ; Wed, 8 Feb 2023 12:02:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EEB13858D39 Received: from fbmtpc21.tugraz.at (fbmtpc21.tugraz.at [129.27.144.40]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4PBdsn1Kp1z3wnl for ; Wed, 8 Feb 2023 13:02:36 +0100 (CET) Message-ID: <932c3fcb674894cbf933fdb679d966487150d81c.camel@tugraz.at> Subject: [PATCH] gimplify size expressions in parameters for all types [PR107557] [PR108423] To: gcc-patches@gcc.gnu.org Date: Wed, 08 Feb 2023 13:02:36 +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=-10.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?1757264275631145399?= X-GMAIL-MSGID: =?utf-8?q?1757264275631145399?= Here is a fix for PR107557 and PR108423. Bootstrapped and regression tested on x86-64. Gimplify more size expression in parameters [PR107557] and [PR108234] gimplify_parm_type only recursives into pointer type and size expressions in other types (e.g. function types) were not reached. PR c/107557 PR c/108234 gcc/Changelog * gcc/function.cc (gimplify_parm_type): Also recursive into non-pointer types. gcc/testsuite/ChangeLog: * gcc.dg/pr107557-1.c: New test. * gcc.dg/pr107557-2.c: New test. * gcc.dg/pr108423-1.c: New test. * gcc.dg/pr108423-2.c: New test. * gcc.dg/pr108423-3.c: New test. * gcc.dg/pr108423-4.c: New test. * gcc.dg/pr108423-5.c: New test. diff --git a/gcc/function.cc b/gcc/function.cc index cfc4d2f74af..d777348aeb4 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -3880,20 +3880,15 @@ static tree gimplify_parm_type (tree *tp, int *walk_subtrees, void *data) { tree t = *tp; - *walk_subtrees = 0; if (TYPE_P (t)) { - if (POINTER_TYPE_P (t)) - *walk_subtrees = 1; - else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t)) + if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t)) && !TYPE_SIZES_GIMPLIFIED (t)) - { - gimplify_type_sizes (t, (gimple_seq *) data); - *walk_subtrees = 1; - } - } + gimplify_type_sizes (t, (gimple_seq *) data); + *walk_subtrees = 1; + } return NULL; } diff --git a/gcc/testsuite/gcc.dg/pr107557-1.c b/gcc/testsuite/gcc.dg/pr107557-1.c new file mode 100644 index 00000000000..88c248b6564 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107557-1.c @@ -0,0 +1,24 @@ +/* PR107557 + * { dg-do compile } + * { dg-options "-flto -fsanitize=undefined -fexceptions -Wno-incompatible-pointer-types" } + */ + + +int c[1][3*2]; +int f(int * const m, int (**v)[*m * 2]) +{ + return &(c[0][*m]) == &((*v)[0][*m]); +} +int test(int n, int (*(*fn)(void))[n]) +{ + return (*fn())[0]; +} +int main() +{ + int m = 3; + int (*d)[3*2] = c; + int (*fn[m])(void); + return f(&m, &d) + test(m, &fn); +} + + diff --git a/gcc/testsuite/gcc.dg/pr107557-2.c b/gcc/testsuite/gcc.dg/pr107557-2.c new file mode 100644 index 00000000000..2d26bb0b16a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107557-2.c @@ -0,0 +1,23 @@ +/* PR107557 + * { dg-do compile } + * { dg-options "-flto -fsanitize=undefined -fexceptions -Wno-incompatible-pointer-types" } + */ + + +int c[1][3*2]; +int f(int * const m, int (**(*v))[*m * 2]) +{ + return &(c[0][*m]) == &((*v)[0][*m]); /* { dg-warning "lacks a cast" } */ +} +int test(int n, int (*(*(*fn))(void))[n]) +{ + return (*(*fn)())[0]; +} +int main() +{ + int m = 3; + int (*d)[3*2] = c; + int (*fn[m])(void); + return f(&m, &d) + test(m, &fn); +} + diff --git a/gcc/testsuite/gcc.dg/pr108423-1.c b/gcc/testsuite/gcc.dg/pr108423-1.c new file mode 100644 index 00000000000..0c98d1d46b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108423-1.c @@ -0,0 +1,16 @@ +/* PR108423 + * { dg-do compile } + * { dg-options "-O2 -Wno-int-conversion -Wno-incompatible-pointer-types" } + */ +int f (int n, int (**(*a)(void))[n]) +{ + return (*a())[0]; +} +int g () +{ + int m = 3; + int (*a[m])(void); + return f(m, &a); +} + + diff --git a/gcc/testsuite/gcc.dg/pr108423-2.c b/gcc/testsuite/gcc.dg/pr108423-2.c new file mode 100644 index 00000000000..006e45a9629 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108423-2.c @@ -0,0 +1,16 @@ +/* PR108423 + * { dg-do compile } + * { dg-options "-O2" } + */ + +void f(int n, int (*a(void))[n]) +{ + (a())[0]; +} + +void g(void) +{ + int (*a(void))[1]; + f(1, a); +} + diff --git a/gcc/testsuite/gcc.dg/pr108423-3.c b/gcc/testsuite/gcc.dg/pr108423-3.c new file mode 100644 index 00000000000..c1987c42b40 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108423-3.c @@ -0,0 +1,17 @@ +/* PR108423 + * { dg-do compile } + * { dg-options "-O2" } + */ + +void f(int n, int (*(*b)(void))[n]) +{ + sizeof (*(*b)()); +} + +int (*a(void))[1]; + +void g(void) +{ + f(1, &a); +} + diff --git a/gcc/testsuite/gcc.dg/pr108423-4.c b/gcc/testsuite/gcc.dg/pr108423-4.c new file mode 100644 index 00000000000..91336f3f283 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108423-4.c @@ -0,0 +1,17 @@ +/* PR108423 + * { dg-do compile } + * { dg-options "-O2" } + */ + +void f(int n, int (*a(void))[n]) +{ + sizeof (*a()); +} + +int (*a(void))[1]; + +void g(void) +{ + f(1, a); +} + diff --git a/gcc/testsuite/gcc.dg/pr108423-5.c b/gcc/testsuite/gcc.dg/pr108423-5.c new file mode 100644 index 00000000000..7e4fffb2870 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108423-5.c @@ -0,0 +1,17 @@ +/* PR108423 + * { dg-do compile } + * { dg-options "-O2" } + */ + +void f(int n, int (*(*a)(void))[n]) +{ + sizeof ((*a)()); +} + +int (*a(void))[1]; + +void g(void) +{ + f(1, a); +} +