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: 65963 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF1D03858436 for ; Fri, 3 Mar 2023 09:46:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF1D03858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677836807; bh=jGIl4FloXBmSZfngV4Cf75hOnYfWa3PKRvEQ5xFdF6A=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Bl/wEkTOX/DxAOB0z0/QICsrSofEx0PRfDWZ+jSTnLp1uwuvBwOIB1lwluIkTCMW0 CfgCZaQtOCjMXCf5SK0jbkOYbUXqnsMlv8/7JwOSH4DMQAupidT8NGmv/iJxchjz7X gx3XmozRQUUCFwRpfL2sSOSV9chZfh6AbJkkgfAI= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; }