From patchwork Sat Sep 30 09:37:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 146898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp288718vqb; Sat, 30 Sep 2023 02:38:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuas4eQUibPmbOQzuNbw3T/B/G2yODrhVTalXTRUkpfvIdiUFdi6LPEwt0HVe94UXNtV7b X-Received: by 2002:a17:906:8a43:b0:9ad:fb23:21d8 with SMTP id gx3-20020a1709068a4300b009adfb2321d8mr6323971ejc.12.1696066714044; Sat, 30 Sep 2023 02:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696066714; cv=none; d=google.com; s=arc-20160816; b=S468GMzNH0I9HmG5Eo51Gyvt6pFyUnEBFR3y/diqqsqFP8qieZKecjoKhHFtwP5nUP /k8fheOIlHOU5aeNM1RfM429ceBzcde6YLyXNpZinPL2O2Y1kyV99Z5xkfC8Ov3CcIO9 ytnzp+SMoCytMQL6hQdQn8c4l/Mpg8Gkd862Gbc5zZw5eOKR83jCLhH69Ye5aWvzNIEF MKhm8btBzJSkl87mne1Affm4ccGGq5LYHglajAbPAqfKXRQgd5Fhf1AsMcFHtJ5lvTVv +fmhPJBHlDFJVoKn1OESVThkOFo50bUm3HXEr+0e2cpvPy6VPryRF2V282ZqnanuiRVp 5F1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :dmarc-filter:delivered-to; bh=d0Qv2TSoTVrz7xEL4oQrb/WSW66mbkAI5Ig20BWQ+Lg=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=DRwRh+S0n+wk01VcgQ81pr/sO6BYUaL3Zgcx+LyZdfpHO+jGDsX3ZSlWke66HDCDMO iSVTr1FfzfoVeYOtIc133hvuv52V7vJXAg3n15KfGPFkm5fg/mg4CyBOLsr/VPVv7waI sBmA49+fN6M8kb33OnI0Whi7whWMGX7RKRlVLOutzF77jhyWiGO/cvVJnKJSC19/JZd1 cXB7DlERPWRrSjhmwbZWp5SlTlMqDaSsPHIVvKzduMkdebIU4xlYjUbUZQwPyVlupCvk HzHoZmwPEC5DwtDF3Bp16EIJXEwtUNIDFG13jhthkRlDlxizy/mJ4JT+IZRhJVfVfSV3 5yuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FAo2NIOp; 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=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a6-20020a1709064a4600b009a0f9f9d779si17182773ejv.436.2023.09.30.02.38.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 02:38:34 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=FAo2NIOp; 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB1F938319C6 for ; Sat, 30 Sep 2023 09:38:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0EA3A3858414 for ; Sat, 30 Sep 2023 09:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EA3A3858414 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696066680; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type; bh=d0Qv2TSoTVrz7xEL4oQrb/WSW66mbkAI5Ig20BWQ+Lg=; b=FAo2NIOpsdN/5+nk3nwZ3e2jfUSsIV/YMX4e4OR/prKWH+qc/4i/7bgBUP1a5JoI1HTZMJ zmQ7Wyqo8d1DzaJvYlAq+AKeDenB55XKUfhKw5X294Fl6HvjYzt2SYDPOueAZEoeKOXjN7 HMUGutI/rA7SgOWn+65cFsrEgNHfz6A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-1qFpducDP0qNGM0_uTz_fw-1; Sat, 30 Sep 2023 05:37:58 -0400 X-MC-Unique: 1qFpducDP0qNGM0_uTz_fw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 791898007A4 for ; Sat, 30 Sep 2023 09:37:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B617140E969 for ; Sat, 30 Sep 2023 09:37:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 38U9btYe3514793 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Sat, 30 Sep 2023 11:37:56 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38U9btJU3514792 for gcc-patches@gcc.gnu.org; Sat, 30 Sep 2023 11:37:55 +0200 Date: Sat, 30 Sep 2023 11:37:55 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] lowerbitint: Fix 2 bitint lowering bugs [PR111625] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778454850567734805 X-GMAIL-MSGID: 1778454850567734805 Hi! This patch fixes 2 issues. One is when we want to get address of an uninitialized large/huge bitint SSA_NAME for multiplication/division/modulo or conversion to floating point (binary or decimal), the code just creates an uninitialized limb sized variable and passes address of that, but I forgot to initialize *prec in that case, so it invoked UB at compile time rather than at runtime. As it is UB, we could use anything valid as precision there, say 2 bits for signed, 1 bit for unsigned as smallest possible set of values, or full bitint precision as full random value. Though, because we only pass address to a single limb, I think it is best to pass the bitsize of the limb. And the other issue is that when ranger in range_to_prec finds some range is undefined_p (), it will assert {lower,upper}_bound () method isn't called on it, but we were. So, the patch adjusts range_to_proc to treat it like the !optimized case, full bitint precision. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-09-30 Jakub Jelinek PR middle-end/111625 PR middle-end/111637 * gimple-lower-bitint.cc (range_to_prec): Use prec or -prec if r.undefined_p (). (bitint_large_huge::handle_operand_addr): For uninitialized operands use limb_prec or -limb_prec precision. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-09-20 09:45:39.000000000 +0200 +++ gcc/gimple-lower-bitint.cc 2023-09-29 16:29:36.541473743 +0200 @@ -1932,7 +1932,8 @@ range_to_prec (tree op, gimple *stmt) unsigned int prec = TYPE_PRECISION (type); if (!optimize - || !get_range_query (cfun)->range_of_expr (r, op, stmt)) + || !get_range_query (cfun)->range_of_expr (r, op, stmt) + || r.undefined_p ()) { if (TYPE_UNSIGNED (type)) return prec; @@ -2066,6 +2067,9 @@ bitint_large_huge::handle_operand_addr ( } else if (gimple_code (g) == GIMPLE_NOP) { + *prec = TYPE_UNSIGNED (TREE_TYPE (op)) ? limb_prec : -limb_prec; + if (prec_stored) + *prec_stored = *prec; tree var = create_tmp_var (m_limb_type); TREE_ADDRESSABLE (var) = 1; ret = build_fold_addr_expr (var);