From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id D84993857359 for ; Fri, 27 May 2022 06:41:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D84993857359 Received: by mail-qt1-x836.google.com with SMTP id hh4so4139210qtb.10 for ; Thu, 26 May 2022 23:41:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=84lkG1fjFBAeZHqKCdU0Sn/ITic7InnvZiRVHOzCjxM=; b=HKeRjVk6R4S1Fenlb6wmZ5Xmc/L68vZ+ytrt7F533jiaVAlxrXjISTi3G63VVvRU5B 56XifyUfIskIf0MkA1/m+g0CIJTTsYnBdIfPSa39rwkssFwVvkb1Q5QIFOtqpSJHe3yc nyZVaiS5BNg6tzPRkwYIPslTC61E4+wlXz+yI+OYMMwy9Mv8qMJDOvLgsCNFWip7Yf7d onRrKS9EcDgbX65xt2EWmZw6thOuaySzqb4xIBm1bIPXvmrFkMeRWpwOc4NYure47m5G ADUL5YvyPRVZ0hsdgkVw/g/t+SjdkawVfbYUxeCxmpgoQDiKFTujePPJgARjIc+X0m7m MqCg== X-Gm-Message-State: AOAM531A7AiHJS77g51XYUVuLX2dhM4uJtsSZ9vOCBlNq/fB6BVg1WJe Je1c8/SE0bhIc9HA44Q1zxZjaJzK7EA+fd4yZVs= X-Google-Smtp-Source: ABdhPJzgkwzZORW0ruEkk+khcHUOCff8oeQ47IQg1LIAGza2Q2ZzY2OZoHmAZrs33XJVYHLvqAKStIdck8QjbW8Gnyk= X-Received: by 2002:a05:622a:64e:b0:2f3:f4a2:f3cb with SMTP id a14-20020a05622a064e00b002f3f4a2f3cbmr32190844qtb.626.1653633664195; Thu, 26 May 2022 23:41:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Fri, 27 May 2022 08:40:52 +0200 Message-ID: Subject: Re: [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639) To: Martin Jambor Cc: GCC Patches , Jan Hubicka Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.6 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, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Fri, 27 May 2022 06:41:07 -0000 On Thu, May 26, 2022 at 4:47 PM Martin Jambor wrote: > > Hi, > > PR 105639 shows that code with type-mismatches can trigger an assert > after runnning into a branch that was inteded only for references to > variables - as opposed to references to functions. Fixed by moving > the condition from the assert to the guarding if statement. > > Bootstrapped and tested on x86_64. OK for trunk and then gcc 12? OK. There's the same assert below - I guess that doesn't need the same treatment? Thanks, Richard. > Thanks, > > Martin > > > > gcc/ChangeLog: > > 2022-05-25 Martin Jambor > > PR ipa/105639 > * ipa-prop.cc (propagate_controlled_uses): Check type of the > constant before adding a LOAD reference. > > gcc/testsuite/ChangeLog: > > 2022-05-25 Martin Jambor > > PR ipa/105639 > * gcc.dg/ipa/pr105639.c: New test. > --- > gcc/ipa-prop.cc | 10 ++++------ > gcc/testsuite/gcc.dg/ipa/pr105639.c | 16 ++++++++++++++++ > 2 files changed, 20 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/ipa/pr105639.c > > diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc > index c6c745f84a0..afd9222b5a2 100644 > --- a/gcc/ipa-prop.cc > +++ b/gcc/ipa-prop.cc > @@ -4187,14 +4187,13 @@ propagate_controlled_uses (struct cgraph_edge *cs) > { > int d = ipa_get_controlled_uses (old_root_info, i); > int c = rdesc->refcount; > + tree cst = ipa_get_jf_constant (jf); > rdesc->refcount = combine_controlled_uses_counters (c, d); > if (rdesc->refcount != IPA_UNDESCRIBED_USE > - && ipa_get_param_load_dereferenced (old_root_info, i)) > + && ipa_get_param_load_dereferenced (old_root_info, i) > + && TREE_CODE (cst) == ADDR_EXPR > + && TREE_CODE (TREE_OPERAND (cst, 0)) == VAR_DECL) > { > - tree cst = ipa_get_jf_constant (jf); > - gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR > - && (TREE_CODE (TREE_OPERAND (cst, 0)) > - == VAR_DECL)); > symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0)); > new_root->create_reference (n, IPA_REF_LOAD, NULL); > if (dump_file) > @@ -4204,7 +4203,6 @@ propagate_controlled_uses (struct cgraph_edge *cs) > } > if (rdesc->refcount == 0) > { > - tree cst = ipa_get_jf_constant (jf); > gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR > && ((TREE_CODE (TREE_OPERAND (cst, 0)) > == FUNCTION_DECL) > diff --git a/gcc/testsuite/gcc.dg/ipa/pr105639.c b/gcc/testsuite/gcc.dg/ipa/pr105639.c > new file mode 100644 > index 00000000000..5534fe93fbf > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ipa/pr105639.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -w" } */ > + > +void typedef (*cb) (void); > + > +static void > +bar (cb *fp) > +{ > + (*fp) (); > +} > + > +void > +foo (void) > +{ > + bar (foo); > +} > -- > 2.36.0 >