From patchwork Fri Mar 3 09:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 63850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp320197wrd; Fri, 3 Mar 2023 01:47:04 -0800 (PST) X-Google-Smtp-Source: AK7set8fB1pktfaS14fQhffk1F3mvJJT9mJmYicHwvvavn8mDl5renKMIQdj8eUdaJ6bjSDfuYbs X-Received: by 2002:a17:906:80c1:b0:8dc:cfe8:da53 with SMTP id a1-20020a17090680c100b008dccfe8da53mr919354ejx.10.1677836823993; Fri, 03 Mar 2023 01:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677836823; cv=none; d=google.com; s=arc-20160816; b=0wxRfEcvQUh1oEqO4AZNdQ+8+2rltb2P0twWKJUd4f5EdQ9Yf16aRumyC0yohAhYm7 XwAwYyeLhEmEVMG+u4Yv+lm1dWPQFE3ltcMjeSSKJ8Ikljd3Ri6sSItHTscM5CnA3yef EGHQFLAk144F+DqkrjwZCKpCaO02NbE6gZHznrRbWKfZDUt7rW/vXgXshgr+LLnAwJ+t OXFy1Kl/4fxyBoWa7xi8/kS7a0Ny6+R/3oI5QuH9J9fO1TTuGdCRF6vMQVD/PMwiDqCG fowE/10sqwk8Q6zDtaEJ7m9JmOv6DOeGeDVbXJyRln95R6GQpSKWwxZCHoPdO9fkV+lM Fznw== 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:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jGIl4FloXBmSZfngV4Cf75hOnYfWa3PKRvEQ5xFdF6A=; b=JxJeBJ9IT19lHSP0wG+opCyXz2qUcoBUwe2OeVD3qwx24fp29kic155nGHQjQ4MaqB FA+n9CEO9XRa9Rw4impGblm5ckQlS8I8PSK8q6aPcyW3oarNb9iRF+r/B6O+c37IfBNT r2V4+T0M9jEumYXj5ZN3vovPb2Yobwqjjjdts6H6P5HdcxnpRMa8wq8Nrhxx7ighCxPA K/0NptfU3LrmE+8atWS0kI+/uY3ajErJmz0vLC9W1pTFMDpq4xo3Ci0fz34myHldEibI WzNN7riXLhD6LOjUmLJ/asOK3rOh+abjdMsKCw38Ejxhk3wSRWKbFjJk8Alct2o8rB9i WnXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="dhq8/+fX"; 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 sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gz10-20020a170906f2ca00b009076178f532si1573369ejb.911.2023.03.03.01.47.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 01:47:03 -0800 (PST) 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="dhq8/+fX"; 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 045B63858425 for ; Fri, 3 Mar 2023 09:47:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 045B63858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677836823; bh=jGIl4FloXBmSZfngV4Cf75hOnYfWa3PKRvEQ5xFdF6A=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dhq8/+fX761QHM4jSgA5MEYCyH+XF1z5yJcUm0M7uGFeV0hcJu9LLloKzOs7oDkn2 gk4oqo9Z6RxL4lYd+94X6HwzyzhKkda28vMa0j7oTAss64thTMCGhWIKV1s54Q+7X8 dNWf2+doZ+6/9TA/CacFhvFwgjOUgb9UsJunX9R0= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id F04543858D33 for ; Fri, 3 Mar 2023 09:46:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F04543858D33 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-20-mm4QIJftNeaoaCx1BR7C_A-1; Fri, 03 Mar 2023 04:46:15 -0500 X-MC-Unique: mm4QIJftNeaoaCx1BR7C_A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5079A1C17433; Fri, 3 Mar 2023 09:46:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F2BA1410DDA; Fri, 3 Mar 2023 09:46:14 +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 3239kC4u1820315 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Mar 2023 10:46:12 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3239kBqS1820314; Fri, 3 Mar 2023 10:46:11 +0100 Date: Fri, 3 Mar 2023 10:46:11 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988] 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.7 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_H2, 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.29 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759339425419538620?= X-GMAIL-MSGID: =?utf-8?q?1759339425419538620?= Hi! gimple_fold_builtin_fputs when folding fputs into fwrite emits the third argument (INTEGER_CST) with incorrect type - get_maxval_strlen or c_strlen return ssizetype, while fwrite argument is size_type_node. The following patch fixes that, I've skimmed through the rest of gimple-fold.cc and in all other places get_maxval_strlen/c_strlen result was fold_converted to size_type_node already (or GIMPLE cast stmt has been emitted directly etc.). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-03 Jakub Jelinek PR tree-optimization/108988 * gimple-fold.cc (gimple_fold_builtin_fputs): Fold len to size_type_node before passing it as argument to fwrite. Formatting fixes. Jakub --- gcc/gimple-fold.cc.jj 2023-02-28 11:38:28.957868160 +0100 +++ gcc/gimple-fold.cc 2023-03-02 10:34:42.791504589 +0100 @@ -2954,8 +2954,7 @@ gimple_fold_builtin_fputs (gimple_stmt_i /* Get the length of the string passed to fputs. If the length can't be determined, punt. */ tree len = get_maxval_strlen (arg0, SRK_STRLEN); - if (!len - || TREE_CODE (len) != INTEGER_CST) + if (!len || TREE_CODE (len) != INTEGER_CST) return false; switch (compare_tree_int (len, 1)) @@ -2972,9 +2971,10 @@ gimple_fold_builtin_fputs (gimple_stmt_i if (!fn_fputc) return false; - gimple *repl = gimple_build_call (fn_fputc, 2, - build_int_cst - (integer_type_node, p[0]), arg1); + gimple *repl + = gimple_build_call (fn_fputc, 2, + build_int_cst (integer_type_node, p[0]), + arg1); replace_call_with_call_and_fold (gsi, repl); return true; } @@ -2990,8 +2990,9 @@ gimple_fold_builtin_fputs (gimple_stmt_i if (!fn_fwrite) return false; - gimple *repl = gimple_build_call (fn_fwrite, 4, arg0, - size_one_node, len, arg1); + gimple *repl + = gimple_build_call (fn_fwrite, 4, arg0, size_one_node, + fold_convert (size_type_node, len), arg1); replace_call_with_call_and_fold (gsi, repl); return true; }