From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9780 invoked by alias); 14 Aug 2015 11:20:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 9764 invoked by uid 89); 14 Aug 2015 11:20:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 14 Aug 2015 11:20:12 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 6F186A0491 for ; Fri, 14 Aug 2015 11:20:11 +0000 (UTC) Received: from redhat.com (ovpn-204-94.brq.redhat.com [10.40.204.94]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7EBK7fQ001008 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 14 Aug 2015 07:20:10 -0400 Date: Fri, 14 Aug 2015 11:51:00 -0000 From: Marek Polacek To: GCC Patches Subject: [PATCH] Fix middle-end/67133, part 1 Message-ID: <20150814112006.GR3335@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-08/txt/msg00780.txt.bz2 As outlined in the PR, this fixes one ICE. The code in question here tries to determine whether OP can be derived as non-NULL. In case the function has the nonnull attribute that applies to all the arguments, we want to see whether OP is in this argument list. But nonnull only appertains to pointers. Some ssa_names don't have a type so check for that first instead of segv before looking at its tree code. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-08-14 Marek Polacek PR middle-end/67133 * gimple.c (infer_nonnull_range_by_attribute): Handle null TREE_TYPE. * g++.dg/torture/pr67133.C: New test. diff --git gcc/gimple.c gcc/gimple.c index cca328a..1482eb4 100644 --- gcc/gimple.c +++ gcc/gimple.c @@ -2678,14 +2678,16 @@ infer_nonnull_range_by_attribute (gimple stmt, tree op) if (attrs == NULL_TREE) return false; - /* If "nonnull" applies to all the arguments, then ARG + /* If "nonnull" applies to all the arguments, then OP is non-null if it's in the argument list. */ if (TREE_VALUE (attrs) == NULL_TREE) { for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++) { - if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt, i))) - && operand_equal_p (op, gimple_call_arg (stmt, i), 0)) + tree arg = gimple_call_arg (stmt, i); + if (TREE_TYPE (arg) != NULL_TREE + && POINTER_TYPE_P (TREE_TYPE (arg)) + && operand_equal_p (op, arg, 0)) return true; } return false; diff --git gcc/testsuite/g++.dg/torture/pr67133.C gcc/testsuite/g++.dg/torture/pr67133.C index e69de29..0f23572 100644 --- gcc/testsuite/g++.dg/torture/pr67133.C +++ gcc/testsuite/g++.dg/torture/pr67133.C @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-additional-options "-fisolate-erroneous-paths-attribute" } + +class A; +struct B { + typedef A type; +}; +template struct I : B {}; +class C { +public: + C(char *); + int size(); +}; +template struct D; +template > class F { + class G { + template static _Tp *__test(); + typedef int _Del; + + public: + typedef decltype(__test<_Del>()) type; + }; + +public: + typename I<_Tp>::type operator*() { + typename G::type a = 0; + return *a; + } +}; +class H { + F Out; + H(); +}; +void fn1(void *, void *, int) __attribute__((__nonnull__)); +class A { + int OutBufEnd, OutBufCur; + +public: + void operator<<(C p1) { + int b, c = p1.size(); + if (OutBufEnd) + fn1(&OutBufCur, &b, c); + } +}; +char* a; +H::H() { *Out << a; } Marek