From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 48E7C383F2D3 for ; Fri, 18 Nov 2022 08:46:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 48E7C383F2D3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x230.google.com with SMTP id l8so5905823ljh.13 for ; Fri, 18 Nov 2022 00:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3WaxXqVurheEbCCyGEZolwRvUga1uEI1Y+RQMChOvyQ=; b=XivRtTopdYVJpoioYKzS/uVVg0AFcIXEtANddPtqlZYRae5o+HGAlwfJVylJV/toKE s8Nyw8G9YcEDy7NwyR5PRcJPsY0ph05/Yt0ODNqV9XhVl9suEA/pLRqHYLhnv/KK6Tna sxM+nInsbAVIhxKR9CzdoLWcP/po1ClspGhBZPor51JoNBycG5RE+IoO4FCPJYvPLMuS NC63v6buNxL90uDa6iNWfkayB1kO/L9d/Y5CoMqY2W+CAftNvVzV88pQ3O3UN21zyuNl vWNIwuGAddShO/2qIIxgO2G1/ZnCkeIrWROH3n8NUsBoUF7nIFrQr+ndIeD9Emjyfoxn V23w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3WaxXqVurheEbCCyGEZolwRvUga1uEI1Y+RQMChOvyQ=; b=R3T1MpRnXXMJZ1JYLVSyFlqUn9gRMm80QKpLLiEA7vf41jGg4+Ejq5SZsgBblZDuLw mfJ3RSTqqlGxuWsXwA7gJIgcl7F4Y0kFU+UrknuettarCBxEAzKFshWOoaVWMwBXC7dZ SQGf5FnBEA/6yjh7a0eOVa5cWdh2RfPYQugh27MUjcvLmChRqNkWNLNwVjdi3yTZarlR ECI5UcdROi7fK8JhukgtK45+L627RAzKQR6NLAJY0BR1W2WZRHzjmAMCeRU03cFnnaSr J1J3TwhpH8ilXHPoyQRslGAZ2xyNs8QxEjaJ+nrfcFifKaNuoFJxY3RttGP4IeyKs5CP AtqA== X-Gm-Message-State: ANoB5plUHVn3U9Ne+zlNN8xwj3Ne+Nabz7ZjdioV6W3J5O1ReRwWOTSq LLem23T2/zf7Bphs247Dpd0Y/oHtUXn7vYG/IP4= X-Google-Smtp-Source: AA0mqf7fb5PFrvsHZvLwUsfXTo1kuoJQxGTH4yOvjTYKz7D88LMvIFys/B315CNeDB3kMtskDuGQed4N0MOEoVDFNE0= X-Received: by 2002:a2e:b5d2:0:b0:26e:1b7:7525 with SMTP id g18-20020a2eb5d2000000b0026e01b77525mr2350124ljn.249.1668761202823; Fri, 18 Nov 2022 00:46:42 -0800 (PST) MIME-Version: 1.0 References: <1668741911-1727-1-git-send-email-apinski@marvell.com> In-Reply-To: <1668741911-1727-1-git-send-email-apinski@marvell.com> From: Richard Biener Date: Fri, 18 Nov 2022 09:46:28 +0100 Message-ID: Subject: Re: [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration To: apinski@marvell.com Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Fri, Nov 18, 2022 at 4:26 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > The problem here is the gimplifier returns GS_ERROR but > in some cases we don't check that soon enough and try > to do other work which could crash. > So the fix in these two cases is to return GS_ERROR > early if the gimplify_* functions had return GS_ERROR. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. > Thanks, > Andrew Pinski > > gcc/ChangeLog: > > PR c/106764 > PR c/106765 > PR c/107307 > * gimplify.cc (gimplify_compound_lval): Return GS_ERROR > if gimplify_expr had return GS_ERROR. > (gimplify_call_expr): Likewise. > > gcc/testsuite/ChangeLog: > > PR c/106764 > PR c/106765 > PR c/107307 > * gcc.dg/redecl-19.c: New test. > * gcc.dg/redecl-20.c: New test. > * gcc.dg/redecl-21.c: New test. > --- > gcc/gimplify.cc | 5 +++++ > gcc/testsuite/gcc.dg/redecl-19.c | 5 +++++ > gcc/testsuite/gcc.dg/redecl-20.c | 9 +++++++++ > gcc/testsuite/gcc.dg/redecl-21.c | 9 +++++++++ > 4 files changed, 28 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/redecl-19.c > create mode 100644 gcc/testsuite/gcc.dg/redecl-20.c > create mode 100644 gcc/testsuite/gcc.dg/redecl-21.c > > diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc > index f06ce3cc77a..c62a966e918 100644 > --- a/gcc/gimplify.cc > +++ b/gcc/gimplify.cc > @@ -3272,6 +3272,8 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval, > fallback | fb_lvalue); > ret = MIN (ret, tret); > + if (ret == GS_ERROR) > + return GS_ERROR; > > /* Step 2a: if we have component references we do not support on > registers then make sure the base isn't a register. Of course > @@ -3709,6 +3711,9 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value) > ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL, > is_gimple_call_addr, fb_rvalue); > > + if (ret == GS_ERROR) > + return GS_ERROR; > + > nargs = call_expr_nargs (*expr_p); > > /* Get argument types for verification. */ > diff --git a/gcc/testsuite/gcc.dg/redecl-19.c b/gcc/testsuite/gcc.dg/redecl-19.c > new file mode 100644 > index 00000000000..cc10685448b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/redecl-19.c > @@ -0,0 +1,5 @@ > +/* We used to ICE in the gimplifier, PR 106764 */ > +/* { dg-do compile } */ > +/* { dg-options "-w" } */ > +(*a)(); // { dg-note "" } > +b(){a()} a; // { dg-error "" } > diff --git a/gcc/testsuite/gcc.dg/redecl-20.c b/gcc/testsuite/gcc.dg/redecl-20.c > new file mode 100644 > index 00000000000..07f52115ec8 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/redecl-20.c > @@ -0,0 +1,9 @@ > +/* We used to ICE in the gimplifier, PR 107307 */ > +// { dg-do compile } > +// { dg-options "-w" } > +void f () > +{ > + const struct { int a[1]; } b; // { dg-note "" } > + int *c = b.a; > + int *b; // { dg-error "" } > +} > diff --git a/gcc/testsuite/gcc.dg/redecl-21.c b/gcc/testsuite/gcc.dg/redecl-21.c > new file mode 100644 > index 00000000000..2f2a6548a57 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/redecl-21.c > @@ -0,0 +1,9 @@ > +/* We used to ICE in the gimplifier, PR 106765 */ > +/* { dg-do compile } */ > +/* { dg-options "-w" } */ > +struct a { > + int b > +} c() { > + struct a a; // { dg-note "" } > + a.b; > + d a; // { dg-error "" } > -- > 2.17.1 >