From patchwork Tue Sep 20 10:07:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 672186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3sddjZ39mnz9t0t for ; Tue, 20 Sep 2016 20:07:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=hp5QuNRH; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Ya5eIzCj/z5Ay2OfVNGmkCngC2AX5Biu2+7JUwq8O/N2uJ+B/t 96CnCWzq3U5wy+YOui10nXYfvRn1bsHh5r+NqowKFsn8pW60i/n3RtBMtLo5G7Vs 8QoMpQ5yYrm1DpZZHM3n4sk9lrRZRDX9F1JhMYYqoQCBI/iMSrgUrxnLo= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=1NbcitP2W0bxQ0bj+zbZs6ohjfc=; b=hp5QuNRHR7RcuulGb0fX htscR7To/HJ/n9jeoWx6Pxvut5RyfsKajx6oU9n1QsOrpK6+WSCJfXjsHhLFN3UF aBonHtHIUrzBD6QosJzpS2LDATzOX0xFCaQ6EFTvJiEz8jxtyGu5Kt6CWnlBb4eW BL7Y6p3I4fHYF1PUhDmrdAg= Received: (qmail 61557 invoked by alias); 20 Sep 2016 10:07:38 -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 61548 invoked by uid 89); 20 Sep 2016 10:07:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy= X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.219) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Sep 2016 10:07:28 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwTPLBCxG2PwtgsgUwIw== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (ip5f581faf.dynamic.kabel-deutschland.de [95.88.31.175]) by smtp.strato.de (RZmta 39.2 DYNA|AUTH) with ESMTPSA id j05dd8s8KA7OQ1p (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 20 Sep 2016 12:07:24 +0200 (CEST) To: GCC Patches Cc: Denis Chertykov , Senthil Kumar Selvaraj From: Georg-Johann Lay Subject: [patch,avr] Fix PR77326: CC_NONE might clobber condition code Message-ID: Date: Tue, 20 Sep 2016 12:07:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes This fixes the case of CC_NONE (insn attribute for cc is "none"): Even in cases where the instructions of an insn do not change the condition code of the machine, they still might change some registers by clobber, set, etc. If one such register overlaps an expression stored in cc_status.value1/2 we must reset cc_status as the value stored there no more represents the state of cc0. Ok to apply and backport? Johann gcc/ PR target/77326 * config/avr/avr.c (avr_notice_update_cc) [CC_NONE]: If insn touches some regs mentioned in cc_status, do CC_STATUS_INIT. gcc/testsuite/ PR target/77326 * gcc.target/avr/torture/pr77326.c: New test. Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 240135) +++ config/avr/avr.c (working copy) @@ -2511,8 +2511,44 @@ avr_notice_update_cc (rtx body ATTRIBUTE break; case CC_NONE: - /* Insn does not affect CC at all. */ - break; + /* Insn does not affect CC at all, but it might set some registers + that are stored in cc_status. If such a register is affected by + the current insn, for example by means of a SET or a CLOBBER, + then we must reset cc_status; cf. PR77326. + + Unfortunately, set_of cannot be used as reg_overlap_mentioned_p + will abort on COMPARE (which might be found in cc_status.value1/2). + Thus work out the registers set by the insn and regs mentioned + in cc_status.value1/2. */ + + if (cc_status.value1 + || cc_status.value2) + { + HARD_REG_SET regs_used; + HARD_REG_SET regs_set; + CLEAR_HARD_REG_SET (regs_used); + + if (cc_status.value1 + && !CONSTANT_P (cc_status.value1)) + { + find_all_hard_regs (cc_status.value1, ®s_used); + } + + if (cc_status.value2 + && !CONSTANT_P (cc_status.value2)) + { + find_all_hard_regs (cc_status.value1, ®s_used); + } + + find_all_hard_reg_sets (insn, ®s_set, false); + + if (hard_reg_set_intersect_p (regs_used, regs_set)) + { + CC_STATUS_INIT; + } + } + + break; // CC_NONE case CC_SET_N: CC_STATUS_INIT; Index: testsuite/gcc.target/avr/torture/pr77326.c =================================================================== --- testsuite/gcc.target/avr/torture/pr77326.c (nonexistent) +++ testsuite/gcc.target/avr/torture/pr77326.c (working copy) @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-Wl,--defsym,test1=0" } */ + +extern void test1 (void) __attribute__((weak)); + +__attribute__((noinline,noclone)) +static void va_pseudo (int flag, ...) +{ + __asm ("nop":); +} + +__attribute__((noinline,noclone)) +static void func (void) +{ + va_pseudo (0, 0, 0, 0); + + if (test1) + __builtin_abort (); +} + +int main (void) +{ + func(); + __builtin_exit (0); + return 0; +}