From patchwork Wed Jun 4 20:06:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Senthil Kumar Selvaraj X-Patchwork-Id: 356084 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 5013A14009C for ; Thu, 5 Jun 2014 06:06:47 +1000 (EST) 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:mime-version:content-type; q=dns; s=default; b=h5PTtOMITl6D0o0XCVvHKTiMMpHhd0/X3cVJd9dPOwxy2XCs0W rzkR/0gBZVdW0TBVdhGbohyEGxK0JOgpJyQnltVPNH/zQRg/qn87ISFEVo+kWGua 9JgSp43U6cPQz834F9cOZgiC3VUqfdqwAmWuj3yjxrEtZ9eTlT0BrF3/k= 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:mime-version:content-type; s= default; bh=evW/awL/Zwsb8t0nkrnMqDaZY3Q=; b=reAHnTJHU/Y37bn/ZiDG rEGLLMXGpm2KzvgIwa2dpEQxAoEC5i5bged8n5N6eJIbaXyHtoDfwzdr9+a8q0t2 npQzdDVXymIDe/GmVk0zgK3icrJ73dIP8fy4LyliYxXL0t1OZtIlBKLGrSr2wGMi 1qZYlNMRUxePK/I8HJ/6t8M= Received: (qmail 8537 invoked by alias); 4 Jun 2014 20:06:40 -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 8524 invoked by uid 89); 4 Jun 2014 20:06:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eusmtp01.atmel.com Received: from eusmtp01.atmel.com (HELO eusmtp01.atmel.com) (212.144.249.243) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Jun 2014 20:06:39 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server id 14.2.347.0; Wed, 4 Jun 2014 22:06:31 +0200 Received: from PENCHT02.corp.atmel.com (10.168.5.162) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server (TLS) id 14.2.347.0; Thu, 5 Jun 2014 04:08:11 +0800 Received: from atmel.com (10.168.5.13) by cas-ap.atmel.com (10.168.5.162) with Microsoft SMTP Server (TLS) id 14.2.342.3; Thu, 5 Jun 2014 04:06:32 +0800 Date: Thu, 5 Jun 2014 01:36:42 +0530 From: Senthil Kumar Selvaraj To: CC: , , Subject: Fix address space computation in expand_debug_expr Message-ID: <20140604200641.GA10914@atmel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes For the AVR target, assertions in convert_debug_memory_address cause a couple of ICEs (see PR 52472). Jakub suggested returning a NULL rtx, which works, but on debugging further, I found that expand_debug_expr appears to incorrectly compute the address space for ADDR_EXPR and MEM_REFs. For ADDR_EXPR, TREE_TYPE(exp) is a POINTER_TYPE (always?), but in the generic address space, even if the object whose address is taken is in a different address space. expand_debug_expr takes TYPE_ADDR_SPACE(TREE_TYPE(exp)) and therefore computes the address space as generic. convert_debug_memory_address then asserts that the mode is a valid pointer mode in the address space and fails. Similarly, for MEM_REFs, TREE_TYPE(exp) is the type of the dereferenced value, and therefore checking if it is a POINTER_TYPE doesn't help for a single pointer dereference. The address space gets computed as generic even if the pointer points to a different address space. The address mode for the generic address space is passed to convert_debug_memory_address, and the assertion that that mode must match the mode of the rtx then fails. The below patch attempts to fix this by picking the right TREE_TYPE to pass to TYPE_ADDR_SPACE for MEM_REF (use type of arg 0) and ADDR_EXPR (check for pointer type and look at nested addr space). Does this look reasonable or did I get it all wrong? Regards Senthil diff --git gcc/cfgexpand.c gcc/cfgexpand.c index 8b0e466..ca78953 100644 --- gcc/cfgexpand.c +++ gcc/cfgexpand.c @@ -3941,8 +3941,8 @@ expand_debug_expr (tree exp) op0 = plus_constant (inner_mode, op0, INTVAL (op1)); } - if (POINTER_TYPE_P (TREE_TYPE (exp))) - as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp))); + if (POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (exp, 0)))) + as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))); else as = ADDR_SPACE_GENERIC; @@ -4467,7 +4467,11 @@ expand_debug_expr (tree exp) return NULL; } - as = TYPE_ADDR_SPACE (TREE_TYPE (exp)); + if (POINTER_TYPE_P (TREE_TYPE (exp))) + as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp))); + else + as = TYPE_ADDR_SPACE (TREE_TYPE (exp)); + op0 = convert_debug_memory_address (mode, XEXP (op0, 0), as); return op0;