From patchwork Mon Sep 24 18:40:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 974044 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-486271-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NFAIxdFG"; dkim-atps=neutral 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 42JtLM0ncjz9s4Z for ; Tue, 25 Sep 2018 04:40:25 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=LDzaJzRQq6kArFHOr7yCNmEpjr0BZAP1g0A9GChDKFSIgYxvZG 2/2AJYbrb3mQUuCcCeuhuBSs9dfgA8EPnJsfmtQab/zDPmvTSHkAI/m/BFTkIxAb a98sXaJNs1MZ/wT+B3RuVLvUge7bkfjkBC67cQa/oWrHJPU4+RTWbgBRE= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=svvL3AjcalW/Q1Xa0U/19TO3Dw4=; b=NFAIxdFGA2rPsRvMbaL0 N0VESOqymFj8mnhLXrb7WDPLJIZhqnV7th/Or5UabcXIf9ziblmB9yPuQyyMc4Cz taz+VmNpBvaAZDCkFUMfHQ3J8kGCmS6HBQaLH302rMx6gWygWGaKplXyyzVumQ7A IHTV261T0a54ejQZgZ7gs/g= Received: (qmail 61209 invoked by alias); 24 Sep 2018 18:40:18 -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 61198 invoked by uid 89); 24 Sep 2018 18:40:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=H*UA:https, Think, i686-linux, i686linux X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Sep 2018 18:40:16 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DDD7EAE87 for ; Mon, 24 Sep 2018 18:40:13 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PR 87347] Prevent segfaults if TYPE_ARG_TYPES is NULL User-Agent: Notmuch/0.26 (https://notmuchmail.org) Emacs/26.1 (x86_64-suse-linux-gnu) Date: Mon, 24 Sep 2018 20:40:13 +0200 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, the warning for suspicious calls of abs-like functions segfaults if a user declared their own parameter-less-ish variant of abs like in the testcase below. Fixed by looking whether there is any TYPE_ARG_TYPES before trying to compare the actual argument with it. Bootstrapped and tested on x86_64-linux and aarch64-linux, the same on i686-linux is pending. OK for trunk? Thanks, Martin 2018-09-24 Martin Jambor PR c/87347 c/ * c-parser.c (warn_for_abs): Bail out if TYPE_ARG_TYPES is NULL. testsuite/ * gcc.dg/pr87347.c: New test. --- gcc/c/c-parser.c | 7 ++++--- gcc/testsuite/gcc.dg/pr87347.c | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr87347.c diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1766a256633..a96d15fef1d 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -9116,9 +9116,10 @@ warn_for_abs (location_t loc, tree fndecl, tree arg) -Wint-conversion warnings. Most other wrong types hopefully lead to type mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P types and possibly other exotic types. */ - if (!INTEGRAL_TYPE_P (atype) - && !SCALAR_FLOAT_TYPE_P (atype) - && TREE_CODE (atype) != COMPLEX_TYPE) + if ((!INTEGRAL_TYPE_P (atype) + && !SCALAR_FLOAT_TYPE_P (atype) + && TREE_CODE (atype) != COMPLEX_TYPE) + || !TYPE_ARG_TYPES (TREE_TYPE (fndecl))) return; enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); diff --git a/gcc/testsuite/gcc.dg/pr87347.c b/gcc/testsuite/gcc.dg/pr87347.c new file mode 100644 index 00000000000..d0bdf2a9fec --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87347.c @@ -0,0 +1,6 @@ +/* {dg-do compile} */ +/* { dg-options "-Wabsolute-value" } */ + +int a; +int abs(); +void b() { abs(a); }