From patchwork Thu Sep 7 09:22:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 137626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2836951vqo; Thu, 7 Sep 2023 02:23:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgj9P+/a+5nH//Zqm+hRNW1PKXVNjEhrTtvLlpgd6L6yZVhzdCqDRHTbQMiuHJMnA+M6vD X-Received: by 2002:a17:906:318d:b0:9a5:b630:a92a with SMTP id 13-20020a170906318d00b009a5b630a92amr3870612ejy.8.1694078621287; Thu, 07 Sep 2023 02:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694078621; cv=none; d=google.com; s=arc-20160816; b=qQKf5MeAot4vJMeXJZZIcdtDI5j7OS9yzy4tZDeApql1z1Dx1UVuAnlqcJuyfiBBaA V/xuZjW2oWcxQh7hT3O+qQVfVTQdDHdAVQhcgfq8+ZgtUCP6Z9Dpq3pPbFlhgVWDnR6o qRXXLLbuINCbroZS8vQDg5wPSQiSMEu8mNQPop7makEvG+Vlh2e/NJnFay/3VLEPszkg WAAWJT6+yOwhKBkzMT958ISwGAbQhyRM8dcU4mYn6K0jJmbPy7rs2cuqTNJ0AWT79gU3 Fxz/pZZxoGgd5z/4rFRtrfu8dQUqt3nZQwb1Gg7e7DypfStv13FKGyYQFhlCLxNzQZcR X1Kg== 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-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=axGSMlP87u9rh2EUk58xkFgSFLgZph6pnlVW8b6mQpw=; fh=oQ9g8G8os2DXGDX6j3u7Rg7tNoygc36+ApAFqgRiHrY=; b=I/D6m/4uyGTpkZE3CBRhRDZA4szYFjYsNvZElcb2nvzBBm1v3TNLLxdPS8t8vQ29pD UpLumtgL8Ro2o2q50Swib1LT/0weQ3k8nAijb+oGEG/y0SXaX8GNyLyoJTQHVBisbRlg RyPAv5A30sayIwgJhyrkv1D8d4K5fYr4zja9qVGdvEXcwKadoIEJwYlP/+hAewp8PuG3 ff0QIV3AVshs+Mjw4jWCaUv0k0Zbdn+4x9QoChpDSEYp0CwH0uqdkX/wvSg2vhETGYbK T2YpXY+5W8EnBtG8ACHDIxlpbRmdVIEYji98cC1G3NDC2zF2lV6x4WLlkgNcfvwPNMQx 1muQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZWab3EDB; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a20-20020a170906685400b00988a9273633si10488148ejs.344.2023.09.07.02.23.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:23:41 -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=@gcc.gnu.org header.s=default header.b=ZWab3EDB; 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 1E50F3858D20 for ; Thu, 7 Sep 2023 09:23:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E50F3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694078620; bh=axGSMlP87u9rh2EUk58xkFgSFLgZph6pnlVW8b6mQpw=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZWab3EDB+EMqr60OveMduCguALNGp89KPMzyBq8RQhn1FyoFOLs/clFRIx6PNN7Kz 6C8vBjW+1wlslx+XuktzX7UQxGlWdrW6tHtyuh+zxivRrYYXZwbIdxA5O97QJmBcl5 FtP/T4l1JqJAGhD9GmD36wDEhAB7nYQGk4uarZEU= 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 ADAAE3858D1E for ; Thu, 7 Sep 2023 09:22:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADAAE3858D1E 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-423-kiIqaJV0O9iQyMJvJKsW0Q-1; Thu, 07 Sep 2023 05:22:53 -0400 X-MC-Unique: kiIqaJV0O9iQyMJvJKsW0Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83A7A1817929; Thu, 7 Sep 2023 09:22:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4375C1121314; Thu, 7 Sep 2023 09:22:52 +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 3879MpkG1998098 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Sep 2023 11:22:51 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3879Mpte1998097; Thu, 7 Sep 2023 11:22:51 +0200 Date: Thu, 7 Sep 2023 11:22:50 +0200 To: Thomas Schwinge Cc: gcc-patches@gcc.gnu.org, Richard Biener Subject: [committed] middle-end: Avoid calling targetm.c.bitint_type_info inside of gcc_assert [PR102989] Message-ID: References: <87o7ietm6l.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 In-Reply-To: <87o7ietm6l.fsf@euler.schwinge.homeip.net> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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, KAM_SHORT, 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: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776370184672165958 X-GMAIL-MSGID: 1776370184672165958 On Thu, Sep 07, 2023 at 10:36:02AM +0200, Thomas Schwinge wrote: > Minor comment/question: are we doing away with the property that > 'assert'-like "calls" must not have side effects? Per 'gcc/system.h', > this is "OK" for 'gcc_assert' for '#if ENABLE_ASSERT_CHECKING' or > '#elif (GCC_VERSION >= 4005)' -- that is, GCC 4.5, which is always-true, > thus the "offending" '#else' is never active. However, it's different > for standard 'assert' and 'gcc_checking_assert', so I'm not sure if > that's a good property for 'gcc_assert' only? For example, see also > "warn about asserts with side effects", or > recent > "RFE: could -fanalyzer warn about assertions that have side effects?". You're right, the #define gcc_assert(EXPR) ((void)(0 && (EXPR))) fallback definition is incompatible with the way I've used it, so for --disable-checking built by non-GCC it would not work properly. Fixed thusly, committed to trunk as obvious. 2023-09-07 Jakub Jelinek PR c/102989 * expr.cc (expand_expr_real_1): Don't call targetm.c.bitint_type_info inside gcc_assert, as later code relies on it filling info variable. * gimple-fold.cc (clear_padding_bitint_needs_padding_p, clear_padding_type): Likewise. * varasm.cc (output_constant): Likewise. * fold-const.cc (native_encode_int, native_interpret_int): Likewise. * stor-layout.cc (finish_bitfield_representative, layout_type): Likewise. * gimple-lower-bitint.cc (bitint_precision_kind): Likewise. Jakub --- gcc/expr.cc.jj 2023-09-06 17:28:24.216977643 +0200 +++ gcc/expr.cc 2023-09-07 11:11:57.761912944 +0200 @@ -11039,7 +11039,8 @@ expand_expr_real_1 (tree exp, rtx target { unsigned int prec = TYPE_PRECISION (type); struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); unsigned int limb_prec = GET_MODE_PRECISION (limb_mode); --- gcc/gimple-fold.cc.jj 2023-09-06 17:28:24.221977578 +0200 +++ gcc/gimple-fold.cc 2023-09-07 11:11:57.765912888 +0200 @@ -4602,7 +4602,8 @@ static bool clear_padding_bitint_needs_padding_p (tree type) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); if (info.extended) return false; scalar_int_mode limb_mode = as_a (info.limb_mode); @@ -4880,7 +4881,8 @@ clear_padding_type (clear_padding_struct case BITINT_TYPE: { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { --- gcc/varasm.cc.jj 2023-09-06 17:28:24.239977342 +0200 +++ gcc/varasm.cc 2023-09-07 11:11:57.769912832 +0200 @@ -5289,8 +5289,8 @@ output_constant (tree exp, unsigned HOST { struct bitint_info info; tree type = TREE_TYPE (exp); - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { --- gcc/fold-const.cc.jj 2023-09-06 17:28:24.219977604 +0200 +++ gcc/fold-const.cc 2023-09-07 11:11:57.772912790 +0200 @@ -7731,8 +7731,8 @@ native_encode_int (const_tree expr, unsi if (TREE_CODE (type) == BITINT_TYPE) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) { @@ -8661,8 +8661,8 @@ native_interpret_int (tree type, const u if (TREE_CODE (type) == BITINT_TYPE) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) { --- gcc/stor-layout.cc.jj 2023-09-06 17:28:24.226977512 +0200 +++ gcc/stor-layout.cc 2023-09-07 11:11:57.775912748 +0200 @@ -2152,7 +2152,8 @@ finish_bitfield_representative (tree rep { struct bitint_info info; unsigned prec = TYPE_PRECISION (TREE_TYPE (field)); - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); unsigned lprec = GET_MODE_PRECISION (limb_mode); if (prec > lprec) @@ -2413,7 +2414,8 @@ layout_type (tree type) { struct bitint_info info; int cnt; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { --- gcc/gimple-lower-bitint.cc.jj 2023-09-06 17:49:21.945490318 +0200 +++ gcc/gimple-lower-bitint.cc 2023-09-07 11:11:57.778912706 +0200 @@ -92,7 +92,8 @@ bitint_precision_kind (int prec) return bitint_prec_middle; struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a (info.limb_mode); if (prec <= GET_MODE_PRECISION (limb_mode)) {