From patchwork Fri Sep 7 21:01:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Trippelsdorf X-Patchwork-Id: 182445 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]) by ozlabs.org (Postfix) with SMTP id C32402C008C for ; Sat, 8 Sep 2012 07:01:55 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347656516; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=7tS71NlZLPdreqJkAmPNEEkPbBE=; b=XUD5yCFHXjs7q+T r4JjcHXGG1fM4j6knzMwaH0UD//GR6g6WVCr0SC8CPLXxp3lYia9/lT/JWGrtNsE 87CxWoVB6SIrPNEEoJ/a21zOMCv90lx8txoZR/RgeBAx97PTc/sb13uXJzgIFS6r jLHcjhW2IMT0cWuLBvN3ZAQc+TKs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=bzR8WGga0QplFtm5OCVoPEWcwCqEkBL96bagsSZIf45hjQP5iW6SG54G8GlyYj PP2SQ2wE7CeEIuzjrRggpeXGsWg9mGYx/3ZGkre2QqeKKQ376wY1MSL09DAl32WD K4x5Nowh4QaksELLYJ8voGNCxWYOMD2na5Fo7MkKuQNbs=; Received: (qmail 3167 invoked by alias); 7 Sep 2012 21:01:52 -0000 Received: (qmail 3154 invoked by uid 22791); 7 Sep 2012 21:01:52 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Sep 2012 21:01:38 +0000 Received: (qmail 17363 invoked from network); 7 Sep 2012 23:01:35 +0200 Received: from unknown (HELO x4) (ud10?360p3@91.65.91.246) by mail.ud10.udmedia.de with ESMTPSA (DHE-RSA-AES256-SHA encrypted, authenticated); 7 Sep 2012 23:01:35 +0200 Date: Fri, 7 Sep 2012 23:01:35 +0200 From: Markus Trippelsdorf To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR54515 Message-ID: <20120907210135.GA3932@x4> MIME-Version: 1.0 Content-Disposition: inline X-IsSubscribed: yes 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 Here the problem is that get_base_address() can return NULL_TREE and this later leads to a segfault. Fix by checking that the return value is valid. gcc-4.6 and 4.7 are also affected. Please commit if this looks OK. Thanks. Tested on x86_64-pc-linux-gnu 2012-09-07 Markus Trippelsdorf PR middle-end/54515 * tree-sra.c (disqualify_base_of_expr): Check for possible NULL_TREE returned by get_base_address() * g++.dg/tree-ssa/pr54515.C: new testcase diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr54515.C b/gcc/testsuite/g++.dg/tree-ssa/pr54515.C new file mode 100644 index 0000000..11ed468 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr54515.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// { dg-options "-O2" } + +template < typename T > T h2le (T) +{ + T a; + unsigned short &b = a; + short c = 0; + unsigned char (&d)[2] = reinterpret_cast < unsigned char (&)[2] > (c); + unsigned char (&e)[2] = reinterpret_cast < unsigned char (&)[2] > (b); + e[0] = d[0]; + return a; +} + +void +bar () +{ + h2le ((unsigned short) 0); +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index aafaa15..2bb92e9 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -984,7 +984,8 @@ static void disqualify_base_of_expr (tree t, const char *reason) { t = get_base_address (t); - if (sra_mode == SRA_MODE_EARLY_IPA + if (t + && sra_mode == SRA_MODE_EARLY_IPA && TREE_CODE (t) == MEM_REF) t = get_ssa_base_param (TREE_OPERAND (t, 0));