From patchwork Tue Dec 13 01:36:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 87784 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1962214qgi; Mon, 12 Dec 2016 17:37:25 -0800 (PST) X-Received: by 10.98.36.195 with SMTP id k64mr99100680pfk.126.1481593045047; Mon, 12 Dec 2016 17:37:25 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x184si45687851pgb.260.2016.12.12.17.37.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 17:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444237-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444237-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444237-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=OFc17LLmdkHCyeDENTsAsf2HZbldVhm0bMu+mVH0RmwUd6qlbr knkW1o4nqxz4a2imUlPTlhSpE+KsmTU2l1ZshcN5R4FSOzQsxUby6FBEZjnFkisJ SyzwHKgYm0rVFGwcbiR7sIsj+k4dlo74aaA0B+497Ox/nuACYR1wkZ6ms= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=Xj5H1ruqJsrkqlteVA3XX+OplFs=; b=U1GFrgHDNuzngZL1gWCW XSOnZBFlTQBBIGSLJcIYM1gt0HmyO635jQLJoyX6ERTI9AhYuzwY9Kzq+EVaqCAZ D4wqdgjfiH1CDB356mDxGrhZ8XLs8b+2RhzlPiNR/yRmKvHaBeNjwuQM9ar8A91f MP29nPXfU4/E6IMAUNmnuqU= Received: (qmail 65705 invoked by alias); 13 Dec 2016 01:36:25 -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 65639 invoked by uid 89); 13 Dec 2016 01:36:24 -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, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=exceed X-HELO: mail-qt0-f178.google.com Received: from mail-qt0-f178.google.com (HELO mail-qt0-f178.google.com) (209.85.216.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Dec 2016 01:36:21 +0000 Received: by mail-qt0-f178.google.com with SMTP id n6so94056977qtd.1 for ; Mon, 12 Dec 2016 17:36:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=J0umpgUn6QhsYsIyI5NGdPR6TcFSKDe8BKCKkEufB2c=; b=hRiwN2GRa+3/StnAXM1Yv11j4wd+REYg8sbnuQjeleYfWMUWASSBEZ7g8av/xXWCPu ePc9gvf7O64lo8nDHF0APPVb0FvW9/9NxuisKHHstAxV4kLClb54s/XXfhVc+tsTMRog n6rhlOwI9d619W1wJTClA4wxM2k0YQvaCY4MGM9EluOaSlLdCDLFmFcmYQmLUyjbATuB 5sD7VmNqbRFiIW3zZhRv5JNApClbfRJgz/r58UEVdK9SKWU9TcLEK0KJYxQWxK0SRzX6 47oIOtrJZQgDeb2pKopXluPy8dp4R+eSXqTeEZbVdk9rePm6ao+AH4HFfRxudyi0njec k+yw== X-Gm-Message-State: AKaTC03zyIH9cHL4mw+5irytCTcBU+uQ7g28IwC1FomCg6QPV4oBN+U2xse724BPjRdzcA== X-Received: by 10.200.54.89 with SMTP id n25mr92857882qtb.82.1481592979280; Mon, 12 Dec 2016 17:36:19 -0800 (PST) Received: from [192.168.0.26] (97-124-188-210.hlrn.qwest.net. [97.124.188.210]) by smtp.gmail.com with ESMTPSA id 33sm27877560qtq.1.2016.12.12.17.36.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 17:36:18 -0800 (PST) To: Gcc Patch List From: Martin Sebor Subject: [PATCH] avoid infinite recursion in maybe_warn_alloc_args_overflow (pr 78775) Message-ID: Date: Mon, 12 Dec 2016 18:36:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-IsSubscribed: yes The attached patch avoids infinite recursion when traversing phi nodes in maybe_warn_alloc_args_overflow by using a bitmap to keep track of those already visited and breaking out. Thanks Martin PR tree-optimization/78775 - ICE in maybe_warn_alloc_args_overflow gcc/ChangeLog: PR tree-optimization/78775 * calls.c (operand_signed_p): Add overload and avoid getting into infinite recursion when traversing phi nodes. gcc/testsuite/ChangeLog: PR tree-optimization/78775 * gcc.dg/pr78775.c: New test. Index: gcc/calls.c =================================================================== --- gcc/calls.c (revision 243581) +++ gcc/calls.c (working copy) @@ -1247,10 +1247,12 @@ alloc_max_size (void) } /* Return true if the type of OP is signed, looking through any casts - to an unsigned type. */ + to an unsigned type. VISITED is expected to be initially null and + is used internally by recursive calls of the function. Caller + must free *VISITED if non-null after the function returns. */ static bool -operand_signed_p (tree op) +operand_signed_p (tree op, bitmap *visited) { if (TREE_CODE (op) == SSA_NAME) { @@ -1265,6 +1267,12 @@ static bool } else if (gimple_code (def) == GIMPLE_PHI) { + if (!*visited) + *visited = BITMAP_ALLOC (NULL); + + if (!bitmap_set_bit (*visited, SSA_NAME_VERSION (op))) + return true; + /* In a phi, a constant argument may be unsigned even if in the source it's signed and negative. Ignore those and consider the result of a phi signed if @@ -1274,7 +1282,7 @@ static bool { tree op = gimple_phi_arg_def (def, i); if (TREE_CODE (op) != INTEGER_CST - && !operand_signed_p (op)) + && !operand_signed_p (op, visited)) return false; } @@ -1285,6 +1293,21 @@ static bool return !TYPE_UNSIGNED (TREE_TYPE (op)); } +/* Return true if the type of OP is signed, looking through any casts + to an unsigned type. */ + +static bool +operand_signed_p (tree op) +{ + bitmap visited = NULL; + bool ret = operand_signed_p (op, &visited); + + if (visited) + BITMAP_FREE (visited); + + return ret; +} + /* Diagnose a call EXP to function FN decorated with attribute alloc_size whose argument numbers given by IDX with values given by ARGS exceed the maximum object size or cause an unsigned oveflow (wrapping) when Index: gcc/testsuite/gcc.dg/pr78775.c =================================================================== --- gcc/testsuite/gcc.dg/pr78775.c (revision 0) +++ gcc/testsuite/gcc.dg/pr78775.c (working copy) @@ -0,0 +1,19 @@ +/* PR c/78775 - [7 Regression] ICE in maybe_warn_alloc_args_overflow + { dg-do compile } + { dg-options "-O2" } */ + +int a, b, *c; + +int main (void) +{ + unsigned long d = 0; + while (1) + { + switch (b) + case 'S': + d = a; + c = __builtin_malloc (d); + } + + return 0; +}