From patchwork Tue Sep 12 14:09:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 812866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461925-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="j2DGToGb"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xs6BB6gyLz9s82 for ; Wed, 13 Sep 2017 00:09:54 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=SJSb103WDxDfbyMe4dbldqHglTt/7StQh1NeSbCd2ngQxLIHB2JEa 4l02FpKfaAULxt7gpGiaCPN5WUZxk3WHp7qGKvTQJZZed1j2oH1HWQLIV2sMKxO7 e/ZReI1YUeo/dFXitjTN37ApbtyjzBCMM72qxS68p42XsyjbxV3sgk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=8BVm6DIVWGFWaWP5ANjKaVFVA70=; b=j2DGToGbMjwbsnwmEXho l/j1Huc2F95G3D7+7yCVmxHMhu7O1jz62FVus5H4NmUtqJrBR6H3/enn2GgPqyY0 dNjnyDcGTyqR8Z6E5ovdDnftxmR7uFdXAzFbQUmay1MyWwKDha7DihsbjkiRjgdo TZ7clXNZdtoeshgcXUDqdiY= Received: (qmail 99339 invoked by alias); 12 Sep 2017 14:09:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 99322 invoked by uid 89); 12 Sep 2017 14:09:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 14:09:44 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D4E12AB43 for ; Tue, 12 Sep 2017 14:09:41 +0000 (UTC) Date: Tue, 12 Sep 2017 16:09:41 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR82129 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following "fixes" PR82129 (hides the issue). It folds writes from uninitialized data to CLOBBERs: - *h5_26(D) = tv_24(D); + *h5_26(D) ={v} {CLOBBER}; Bootstrap & regtest running on x86_64-unknown-linux-gnu. Richard. 2017-09-12 Richard Biener PR tree-optimization/82129 * gimple-fold.c (fold_gimple_assign): Fold stores from undefined values to clobbers. * gcc.dg/torture/pr82129.c: New testcase. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 252002) +++ gcc/gimple-fold.c (working copy) @@ -410,6 +410,20 @@ fold_gimple_assign (gimple_stmt_iterator else if (DECL_P (rhs)) return get_symbol_constant_value (rhs); + + else if (TREE_CODE (rhs) == SSA_NAME + && SSA_NAME_IS_DEFAULT_DEF (rhs) + && ! ssa_defined_default_def_p (rhs) + && gimple_store_p (stmt) + && ! gimple_has_volatile_ops (stmt)) + { + /* Replace a store from an undefined value with a clobber + which will not generate code, thus avoid doing this when + the store is volatile. */ + tree clobber = build_constructor (TREE_TYPE (rhs), NULL); + TREE_THIS_VOLATILE (clobber) = true; + return clobber; + } } break; Index: gcc/testsuite/gcc.dg/torture/pr82129.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr82129.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr82129.c (working copy) @@ -0,0 +1,51 @@ +/* { dg-do compile } */ + +int pj; + +void +g4 (unsigned long int *bc, unsigned long int *h5) +{ + if (pj != 0) + { + int ib = 0; + + while (bc != 0) + { +m6: + for (pj = 0; pj < 2; ++pj) + pj = 0; + + while (pj != 0) + { + for (;;) + { + } + + while (ib != 0) + { + unsigned long int tv = *bc; + unsigned long int n7; + + *bc = 1; + while (*bc != 0) + { + } + +ut: + if (pj == 0) + n7 = *h5 > 0; + else + { + *h5 = tv; + n7 = *h5; + } + ib += n7; + } + } + } + + goto ut; + } + + goto m6; +}