From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id AF64F3858D20 for ; Fri, 31 Mar 2023 08:57:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF64F3858D20 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-lf1-x130.google.com with SMTP id h11so21026185lfu.8 for ; Fri, 31 Mar 2023 01:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680253041; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9vNlK1IvvN4RSiWJ2nRh85wIXhASSB22H5TEmEYTipg=; b=jrmBza3THj8Bh8xuKSTJ7g3Me4/HafBMJ09P+ODyQQWsDCxrit5oPW/hyn2AdIS1SN NoQKwWQIZB3m3wbhHekTCVTA3Xu05KpD3ubNkdxudI7s04TgC9WgPCBa2PEIDlMrG9PZ XWMmRM3LWW9gK5drIQFS7OjUT8c4T/PDjtk9ciMrIs4RfcIkq0VXr8ofgBybXuVSHlsh 8SpU+hrjKs2fNutMnWUq52hTLK3dm4DM3ZhKY4P08ZCkZjeGpPBpIODrtzOVSag8aIsw Adj6twgOxgBiskxZUPKK1qDalKhLHpd1X/YWWSbfeJADhq/I6Gzyy24sencYcOb9ToO5 fWvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680253041; h=content-transfer-encoding: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=9vNlK1IvvN4RSiWJ2nRh85wIXhASSB22H5TEmEYTipg=; b=KCfEo41oTzXhvrvchWPBO5PYvEGLvc7M/dSJbTLZTU1RLIpfhKtlbPPanIeYCBUPkk 927I+e4nmC43lYzGnPmQ6y8stYWGJmEJre8HkU2wrYca6cboQcccurWduSYLT7HSYylh w4vfozOsJxLbIuoC/a4BBhNDhfkiYuu7hL+fOBFLNVo4nhESDPlakDzBg4jYjzR+/CQm j5IfWHmBq+UTTDVC+LFcH2dS9LPxY7SqANn9/6ErZkPwLw4JI+o8N7dqkgShijlgjEyL d6JF5peHial3PgUIM0xkGU2qmkR8J06nAlLtavShHmBGQPd7RYt13gzZpdvFLpcP/+8K v8zg== X-Gm-Message-State: AAQBX9dz7B/NEFv6Ac4kTgXwxGmkKv2mmDKaWbFR2I2uunj6FA7ol+Fp yxbGEy/fXKS8+nkHIlFimwnLms+g7lMo1Gj0ouw= X-Google-Smtp-Source: AKy350bf9cGUD+E6DCO3sxZ99YnK7M/hY52Dbeg8n0EUlkXVPtcRobK8jaqhqorfzyE4EVlBJEYGHjqbGw39yngS8jY= X-Received: by 2002:ac2:5a06:0:b0:4e8:45d5:53cd with SMTP id q6-20020ac25a06000000b004e845d553cdmr7611409lfn.12.1680253041112; Fri, 31 Mar 2023 01:57:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Fri, 31 Mar 2023 10:57:08 +0200 Message-ID: Subject: Re: [PATCH] ipa: Avoid constructing aggregate jump functions with huge offsets (PR 109303) To: Martin Jambor Cc: GCC Patches , Jan Hubicka Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 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, Mar 31, 2023 at 10:46=E2=80=AFAM Martin Jambor wr= ote: > > Hi, > > we are in the process of changing data structures holding information > about constants passed by reference and in aggregates to use unsigned > int offsets rather than HOST_WIDE_INT (which was selected simply > because that is what fell out of get_ref_base_and_extent at that time) > in order to conserve memory, especially at WPA time. > > PR 109303 testcase discovers that we do not properly check that we > only create jump functions with offsets (plus sizes) that fit into the > smaller type. This patch adds the necessary check. > > Bootstrapped and tested on x86_64-linux. OK for master? > > Thanks, > > Martin > > > gcc/ChangeLog: > > 2023-03-30 Martin Jambor > > PR ipa/109303 > * ipa-prop.cc (determine_known_aggregate_parts): Check that the > offset + size will be representable in unsigned int. > > gcc/testsuite/ChangeLog: > > 2023-03-30 Jakub Jelinek > Martin Jambor > > PR ipa/109303 > * gcc.dg/pr109303.c: New test. > --- > gcc/ipa-prop.cc | 4 +++- > gcc/testsuite/gcc.dg/pr109303.c | 24 ++++++++++++++++++++++++ > 2 files changed, 27 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.dg/pr109303.c > > diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc > index de45dbccf16..9ffd49b590c 100644 > --- a/gcc/ipa-prop.cc > +++ b/gcc/ipa-prop.cc > @@ -2086,7 +2086,9 @@ determine_known_aggregate_parts (struct ipa_func_bo= dy_info *fbi, > whether its value is clobbered any other dominating one. */ > if ((content->value.pass_through.formal_id >=3D 0 > || content->value.pass_through.operand) > - && !clobber_by_agg_contents_list_p (all_list, content)) > + && !clobber_by_agg_contents_list_p (all_list, content) > + && (content->offset + content->size - arg_offset > + <=3D (HOST_WIDE_INT) UINT_MAX * BITS_PER_UNIT)) > { it does seem a bit misplaced since after the if we add the same 'content' to another list anyway. Wouldn't a more obvious place be where we end up truncating this sum? > struct ipa_known_agg_contents_list *copy > =3D XALLOCA (struct ipa_known_agg_contents_list); > diff --git a/gcc/testsuite/gcc.dg/pr109303.c b/gcc/testsuite/gcc.dg/pr109= 303.c > new file mode 100644 > index 00000000000..f91535991c7 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr109303.c > @@ -0,0 +1,24 @@ > +/* PR ipa/109303 */ > +/* { dg-do compile { target lp64 } } */ > +/* { dg-options "-O2" } */ > + > +struct __attribute__((packed)) A { char c1; short a1[__INT_MAX__]; }; > +struct __attribute__((packed)) B { char c2; short a2[100]; }; > +struct S { struct A p1; struct B p2[4]; }; > +void bar (short int); > + > +static void > +foo (struct S *q) > +{ > + for (int i =3D 0; i < q->p1.c1; i++) > + for (int j =3D 0; j < q->p2[i].c2; j++) > + bar (q->p2[i].a2[j]); > +} > + > +int > +main () > +{ > + struct S q =3D {}; > + q.p2[0].c2 =3D q.p2[1].c2 =3D 3; > + foo (&q); > +} > -- > 2.40.0 >