From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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=1677836779; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=jGIl4FloXBmSZfngV4Cf75hOnYfWa3PKRvEQ5xFdF6A=; b=Q7ooDSEdn2b0FVbdlHp7ucHdqI/UFHIfnMRwqnAJXAHXAEz24w4wf2AhDPrrFfIQV3BB13 +6wH6Lq+rnHvgyxRlg9z8i8KTT12ut1m9hdgAlypTqoQjoZg2yzGuD1XRlxMkuiq83g8O0 ZYgTffRM3PDu0UJ0X/qcncmNIBJAB+I= 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 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988] Message-ID: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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; } Jakub