From patchwork Fri Aug 14 15:27:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 507467 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 ACDF61401EF for ; Sat, 15 Aug 2015 01:27:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eMorlR7A; dkim-atps=neutral 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=IUfn9Mi6PGrXC9KgaO1vMX21Yw4iTd/CDkYDG7ZQetsFecP82xh3m ZuhAMH7HH7U/2Nb7s/3LBr/715fOY3ahGeR8di6M6kNkTeXYVgevQrmYWGy+Reqv cYcEkV2nFDhAbPPguuMCqS6tWgPgBv3ui+BWO2psFKux4yRLDWSgfg= 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:subject:message-id:mime-version:content-type; s= default; bh=0WV2wJ+g++mXJRXA8S0qRoXzpsM=; b=eMorlR7A9yEMHogJvD+1 +vnzotE+MRvjQ9hyJZm7Twrw8Im/qAhn+89Mdo5csEAdXTTlQrd3qk7Ek/iYLDfT CJwl1h4sEihmO9Sqxef+55hniWU+28ZQ4A5o0QzasljYJRQTdg8vhO1JwxYT8W7w XcsCLRtC+xE8YAMuhXtWOt8= Received: (qmail 32370 invoked by alias); 14 Aug 2015 15:27:22 -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 32359 invoked by uid 89); 14 Aug 2015 15:27:21 -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 15:27:20 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 7C98A394D3B for ; Fri, 14 Aug 2015 15:27:19 +0000 (UTC) Received: from redhat.com (ovpn-204-94.brq.redhat.com [10.40.204.94]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7EFRGAY020667 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 14 Aug 2015 11:27:18 -0400 Date: Fri, 14 Aug 2015 17:27:15 +0200 From: Marek Polacek To: GCC Patches Subject: [PATCH] Fix middle-end/67133, part 2 Message-ID: <20150814152715.GT3335@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This is the second fix for this PR. Here the problem was that we were accessing arguments that don't exist. We first need to check that the call stmt has sufficient number of arguments. For details see the PR. 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): Check that the nonnull argument position is not outside function arguments. * gcc.dg/torture/pr67133.c: New test. Marek diff --git gcc/gimple.c gcc/gimple.c index cca328a..1bfa8c7 100644 --- gcc/gimple.c +++ gcc/gimple.c @@ -2694,10 +2694,13 @@ infer_nonnull_range_by_attribute (gimple stmt, tree op) /* Now see if op appears in the nonnull list. */ for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t)) { - int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1; - tree arg = gimple_call_arg (stmt, idx); - if (operand_equal_p (op, arg, 0)) - return true; + unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1; + if (idx < gimple_call_num_args (stmt)) + { + tree arg = gimple_call_arg (stmt, idx); + if (operand_equal_p (op, arg, 0)) + return true; + } } } } diff --git gcc/testsuite/gcc.dg/torture/pr67133.c gcc/testsuite/gcc.dg/torture/pr67133.c index e69de29..4eb552e 100644 --- gcc/testsuite/gcc.dg/torture/pr67133.c +++ gcc/testsuite/gcc.dg/torture/pr67133.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fisolate-erroneous-paths-attribute" } */ + +int printf (const char *, ...); +int foo (int); + +int a, *b, c; + +static int +fn1 () +{ + if (a) + return (a = 0); + for (; a; ) + a = 0; + return 0; +} + +static int +fn2 (int p) +{ + fn1 (); + c = 0; + if (p) + printf ("%d", 0); + foo (b != &p); + return 0; +} + +void +fn3 () +{ + fn2 (0); +}