From patchwork Thu Oct 22 16:24:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 55445 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 257A022AA5 for ; Thu, 22 Oct 2015 16:25:00 +0000 (UTC) Received: by wikv3 with SMTP id v3sf36901923wik.1 for ; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to :subject:content-type:x-original-sender :x-original-authentication-results; bh=WPfU8yA/W1PNDLKL0Kx8q6zxX9bMtf3yxRxPTOC9ERU=; b=eCJg0eo3suJRmkELOCGuM8PZsZJQV2jLuRmMJhqqSjvM1DLVLBeZi4lWXyIXD+sQd9 b+W+c2NzXJ1NwCWL+hF7YPcjLvn1RFtr6UA/5HwOVRmyorm4zcL64rhXEg8y68DGdLpj 2e2DFdvUeWvYqUkXvPE+e5uWPzPHKZQZEw09nh6PHQPibT9rh354i7lJaRlyt20OO1W6 HziTkF9hH+CPmtgnqVJHBlyqEQv1cQKADpH7a6s8S9DWiTc+Il3h1iJvEotZYguvSF3/ 4NvwYABak+hlEYKxWSAxxWlCYivLefN3H86lIG60MKdV6LJfegrau5xry8Qq90WPEDrq xAUQ== X-Gm-Message-State: ALoCoQm0yYMRkc9w44SQs/f3OnTyzOuxfeH8wu//7wHxTFUUPpKTUy/9wDZulg9zLKjog7pKSr/q X-Received: by 10.112.55.69 with SMTP id q5mr3853682lbp.24.1445531099400; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.24.170 with SMTP id 42ls373042lfy.3.gmail; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) X-Received: by 10.112.163.193 with SMTP id yk1mr8725968lbb.1.1445531099247; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) Received: from mail-lf0-x22e.google.com (mail-lf0-x22e.google.com. [2a00:1450:4010:c07::22e]) by mx.google.com with ESMTPS id xe5si10111464lbb.65.2015.10.22.09.24.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 09:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) client-ip=2a00:1450:4010:c07::22e; Received: by lfbn126 with SMTP id n126so20074545lfb.2 for ; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) X-Received: by 10.25.20.24 with SMTP id k24mr5950104lfi.117.1445531099125; Thu, 22 Oct 2015 09:24:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp702668lbq; Thu, 22 Oct 2015 09:24:57 -0700 (PDT) X-Received: by 10.68.217.8 with SMTP id ou8mr18619629pbc.164.1445531097782; Thu, 22 Oct 2015 09:24:57 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id yf8si22141523pbc.129.2015.10.22.09.24.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 09:24:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-411079-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 3208 invoked by alias); 22 Oct 2015 16:24:44 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 3198 invoked by uid 89); 22 Oct 2015 16:24:44 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Oct 2015 16:24:42 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-25-vnw62I0vSg-L2GYeRI2gIw-1; Thu, 22 Oct 2015 17:24:38 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 22 Oct 2015 17:24:37 +0100 Message-ID: <56290DC5.1090904@arm.com> Date: Thu, 22 Oct 2015 17:24:37 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches Subject: [PATCH][optabs.c] Fix PR 67989: Handle const0_rtx target in expand_atomic_compare_and_swap X-MC-Unique: vnw62I0vSg-L2GYeRI2gIw-1 X-IsSubscribed: yes X-Original-Sender: kyrylo.tkachov@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi all, The ICE in this PR (reduced from LLVM) occurs because the atomic_load builtin expansion ends up calling expand_atomic_compare_and_swap without caring about the result. The convention in the optabs/builtin machinery is to use const0_rtx for the target destination when that is the case. However, expand_atomic_compare_and_swap didn't check for that, only for the case where the pointer to the target is NULL. This patch fixes that by handling the case where the ptarget_oval and ptarget_bool pointers are not-NULL but contain const0_rtx. N.B. This is one of the fallback paths for expanding atomic_load when the target doesn't provide expanders for it, like the arm target with -march=armv4t. Bootstrapped and tested on arm-none-linux-gnueabihf, aarch64-linux-gnu, x86_64-unknown-linux-gnu. This ICE appears on the GCC 5 and GCC 4.9 branch. I'll be bootstrapping and testing this patch on those branches. Meanwhile, is this ok for trunk? Thanks, Kyrill 2015-10-22 Kyrylo Tkachov PR middle-end/67989 * optabs.c (expand_atomic_compare_and_swap): Handle case when ptarget_oval or ptarget_bool are const0_rtx. 2015-10-22 Kyrylo Tkachov PR middle-end/67989 * g++.dg/pr67989.C: New test. commit 91e5931f48da3377684328b5c00ce4c46ff82365 Author: Kyrylo Tkachov Date: Thu Oct 22 14:21:28 2015 +0100 [optabs.c] Fix PR 67989: Handle const0_rtx target in expand_atomic_compare_and_swap diff --git a/gcc/optabs.c b/gcc/optabs.c index 950ee3c..acb3120 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -5852,9 +5852,9 @@ expand_atomic_exchange (rtx target, rtx mem, rtx val, enum memmodel model) *PTARGET_BOOL is an optional place to store the boolean success/failure. *PTARGET_OVAL is an optional place to store the old value from memory. - Both target parameters may be NULL to indicate that we do not care about - that return value. Both target parameters are updated on success to - the actual location of the corresponding result. + Both target parameters may be NULL or const0_rtx to indicate that we do + not care about that return value. Both target parameters are updated on + success to the actual location of the corresponding result. MEMMODEL is the memory model variant to use. @@ -5879,6 +5879,9 @@ expand_atomic_compare_and_swap (rtx *ptarget_bool, rtx *ptarget_oval, /* Make sure we always have some place to put the return oldval. Further, make sure that place is distinct from the input expected, just in case we need that path down below. */ + if (ptarget_oval && *ptarget_oval == const0_rtx) + ptarget_oval = NULL; + if (ptarget_oval == NULL || (target_oval = *ptarget_oval) == NULL || reg_overlap_mentioned_p (expected, target_oval)) @@ -5889,6 +5892,9 @@ expand_atomic_compare_and_swap (rtx *ptarget_bool, rtx *ptarget_oval, { machine_mode bool_mode = insn_data[icode].operand[0].mode; + if (ptarget_bool && *ptarget_bool == const0_rtx) + ptarget_bool = NULL; + /* Make sure we always have a place for the bool operand. */ if (ptarget_bool == NULL || (target_bool = *ptarget_bool) == NULL diff --git a/gcc/testsuite/g++.dg/pr67989.C b/gcc/testsuite/g++.dg/pr67989.C new file mode 100644 index 0000000..90261c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr67989.C @@ -0,0 +1,75 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c++11 -O2" } */ +/* { dg-additional-options "-marm -march=armv4t" { target arm*-*-* } } */ + +__extension__ typedef unsigned long long int uint64_t; +namespace std __attribute__ ((__visibility__ ("default"))) +{ + typedef enum memory_order + { + memory_order_seq_cst + } memory_order; +} + +namespace std __attribute__ ((__visibility__ ("default"))) +{ + template < typename _Tp > struct atomic + { + static constexpr int _S_min_alignment + = (sizeof (_Tp) & (sizeof (_Tp) - 1)) || sizeof (_Tp) > 16 + ? 0 : sizeof (_Tp); + static constexpr int _S_alignment + = _S_min_alignment > alignof (_Tp) ? _S_min_alignment : alignof (_Tp); + alignas (_S_alignment) _Tp _M_i; + operator _Tp () const noexcept + { + return load (); + } + _Tp load (memory_order __m = memory_order_seq_cst) const noexcept + { + _Tp tmp; + __atomic_load (&_M_i, &tmp, __m); + } + }; +} + +namespace lldb_private +{ + namespace imp + { + } + class Address; +} +namespace lldb +{ + typedef uint64_t addr_t; + class SBSection + { + }; + class SBAddress + { + void SetAddress (lldb::SBSection section, lldb::addr_t offset); + lldb_private::Address & ref (); + }; +} +namespace lldb_private +{ + class Address + { + public: + const Address & SetOffset (lldb::addr_t offset) + { + bool changed = m_offset != offset; + } + std::atomic < lldb::addr_t > m_offset; + }; +} + +using namespace lldb; +using namespace lldb_private; +void +SBAddress::SetAddress (lldb::SBSection section, lldb::addr_t offset) +{ + Address & addr = ref (); + addr.SetOffset (offset); +}