From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102415 invoked by alias); 15 Feb 2018 00:49:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 101492 invoked by uid 89); 15 Feb 2018 00:49:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Feb 2018 00:49:33 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EAD97C81E for ; Thu, 15 Feb 2018 00:49:22 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-85.brq.redhat.com [10.40.204.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36133202348A for ; Thu, 15 Feb 2018 00:49:21 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w1F04W0s006841; Thu, 15 Feb 2018 01:04:32 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w1F04U7x006840; Thu, 15 Feb 2018 01:04:30 +0100 Date: Thu, 15 Feb 2018 00:49:00 -0000 From: Jakub Jelinek To: Richard Biener , Jeff Law , Martin Sebor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383) Message-ID: <20180215000430.GE5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00889.txt.bz2 Hi! The function calls get_addr_base_and_unit_offset on 2 trees, but that can return NULL if the unit offset is not constant. The conditional tests just one of them for non-NULL and operand_equal_p ICEs if one argument is NULL, so depending on the uninitialized poly_int64 (get_addr_base_and_unit_offset doesn't touch it if it returns NULL), we either ICE in operand_equal_p or are lucky and dstoff is equal to lhsoff and just valgrind complains. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-02-15 Jakub Jelinek PR tree-optimization/84383 * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Don't look at dstoff nor call operand_equal_p if dstbase is NULL. * gcc.c-torture/compile/pr84383.c: New test. --- gcc/tree-ssa-strlen.c.jj 2018-02-09 06:44:29.993809176 +0100 +++ gcc/tree-ssa-strlen.c 2018-02-14 16:38:36.981713666 +0100 @@ -1878,6 +1878,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_it poly_int64 lhsoff; tree lhsbase = get_addr_base_and_unit_offset (lhs, &lhsoff); if (lhsbase + && dstbase && known_eq (dstoff, lhsoff) && operand_equal_p (dstbase, lhsbase, 0)) return false; --- gcc/testsuite/gcc.c-torture/compile/pr84383.c.jj 2018-02-14 17:33:21.972803287 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr84383.c 2018-02-14 17:32:37.639803918 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/84383 */ + +struct S { char *s; }; +void bar (struct S *); + +void +foo (int a, char *b) +{ + struct S c[4]; + bar (c); + __builtin_strncpy (c[a].s, b, 32); + c[a].s[31] = '\0'; + bar (c); +} Jakub