From patchwork Mon Nov 6 21:35:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 834952 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-466073-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="QnC2kJTj"; 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 3yW5TS5jrSz9ryv for ; Tue, 7 Nov 2017 08:35:56 +1100 (AEDT) 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=G1hJkp7TYAFp130pDluQYWz2i1+E2 qka8lfcupguDdCLdD8ZWf1haG/a+WFzT4v15C901y1SR+2D3UKGxA5tM/psCNU8L g9VtlYxgHsBjVBl43AjCwzxsBw1Cc7I8R6lS7tw51cEUVZms6EriUEFl9luwuVmx m/Q70D9XKBYNQU= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=BYnF7GAMoI6z0ajEJz3qAhqzzOo=; b=QnC 2kJTjxlk0/WbIowIsg0lZgo/RlY6qg0sNf4P8emT5JT5Dvwe2OX2cNvRQiXrnSHq vtMwr9MV0+3ewXIbatwaL31urbqqKqx8/hqr6gTqz0UEbYZF3aFSZLxz8pGoJGpB NCITjmZNzlGNJFzG11Os/E0L1/fpHGM8i0TyNTyY= Received: (qmail 118691 invoked by alias); 6 Nov 2017 21:35: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 118681 invoked by uid 89); 6 Nov 2017 21:35:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=validate, assemble X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Nov 2017 21:35:45 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F8BD37E6E for ; Mon, 6 Nov 2017 21:35:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F8BD37E6E Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A869B5D9C9; Mon, 6 Nov 2017 21:35:43 +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 vA6LZfR7005326; Mon, 6 Nov 2017 22:35:41 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vA6LZehj005325; Mon, 6 Nov 2017 22:35:40 +0100 Date: Mon, 6 Nov 2017 22:35:40 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix dwarf2out ICE with UNSPEC_GOTOFF (PR debug/82837) Message-ID: <20171106213540.GB14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! My recent changes to const_ok_for_output_1 to allow UNSPEC if target hook says it is ok for debug regressed the following testcase, where creative simplify-rtx.c changes result in (const (neg (unspec ... UNSPEC_GOTOFF))) being emitted and the backend not being able to assemble that (assembler has no such relocations). We already have a hack to avoid ICEing on NOT in similar cases, this patch adds NEG to that. And, in mem_loc_descriptor tries harder to handle these cases right - while if we have say (const (not (symbol_ref))) the current code would handle it right already, if there is the unspec, we really need it to be wrapped inside of CONST, otherwise it is dropped on the floor. The patch in that case emits (const (neg (unspec ... UNSPEC_GOTOFF))) as (neg (const (unspec ... UNSPEC_GOTOFF))). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-06 Jakub Jelinek PR debug/82837 * dwarf2out.c (const_ok_for_output_1): Reject NEG in addition to NOT. (mem_loc_descriptor): Handle (const (neg (...))) as (neg (const (...))) and similarly for not instead of neg. * gcc.dg/debug/dwarf2/pr82837.c: New test. Jakub --- gcc/dwarf2out.c.jj 2017-11-01 22:49:18.000000000 +0100 +++ gcc/dwarf2out.c 2017-11-06 18:52:28.047287983 +0100 @@ -13782,10 +13782,14 @@ const_ok_for_output_1 (rtx rtl) We should really identify / validate expressions enclosed in CONST that can be handled by assemblers on various targets and only handle legitimate cases here. */ - if (GET_CODE (rtl) != SYMBOL_REF) + switch (GET_CODE (rtl)) { - if (GET_CODE (rtl) == NOT) - return false; + case SYMBOL_REF: + break; + case NOT: + case NEG: + return false; + default: return true; } @@ -14958,8 +14962,32 @@ mem_loc_descriptor (rtx rtl, machine_mod if (!const_ok_for_output (rtl)) { if (GET_CODE (rtl) == CONST) - mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode, - mem_mode, initialized); + switch (GET_CODE (XEXP (rtl, 0))) + { + case NOT: + op = DW_OP_not; + goto try_const_unop; + case NEG: + op = DW_OP_neg; + goto try_const_unop; + try_const_unop: + rtx arg; + arg = XEXP (XEXP (rtl, 0), 0); + if (!CONSTANT_P (arg)) + arg = gen_rtx_CONST (int_mode, arg); + op0 = mem_loc_descriptor (arg, int_mode, mem_mode, + initialized); + if (op0) + { + mem_loc_result = op0; + add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0)); + } + break; + default: + mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode, + mem_mode, initialized); + break; + } break; } --- gcc/testsuite/gcc.dg/debug/dwarf2/pr82837.c.jj 2017-11-06 18:38:19.365703290 +0100 +++ gcc/testsuite/gcc.dg/debug/dwarf2/pr82837.c 2017-11-06 18:52:07.759536945 +0100 @@ -0,0 +1,29 @@ +/* PR debug/82837 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -g" } */ +/* { dg-additional-options "-march=athlon" { target ia32 } } */ +/* { dg-additional-options "-fPIE" { target pie } } */ + +static char b[100]; +static int *c; +char *e; +void a(char *f, char *i) { + int d = __builtin_object_size(f, 1); + __builtin___strcpy_chk(f, i, d); +} +void g(void) { + int h; + switch (*c) { + case 8: + e = "swapgs"; + break; + case 9: + e = "rdtscp"; + break; + default: + return; + } + h = __builtin_strlen(b); + a(b + h - 6, e); + c++; +}