From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115605 invoked by alias); 25 Sep 2018 15:47:54 -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 115537 invoked by uid 89); 25 Sep 2018 15:47:53 -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= 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; Tue, 25 Sep 2018 15:47:52 +0000 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F13B6AF60; Tue, 25 Sep 2018 15:47:49 +0000 (UTC) From: Martin Jambor To: Jakub Jelinek Cc: GCC Patches Cc: Subject: Re: [PR 87347] Prevent segfaults if TYPE_ARG_TYPES is NULL In-Reply-To: <20180925090540.GB8250@tucnak> References: <20180925090540.GB8250@tucnak> User-Agent: Notmuch/0.26 (https://notmuchmail.org) Emacs/26.1 (x86_64-suse-linux-gnu) Date: Tue, 25 Sep 2018 15:50:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg01455.txt.bz2 Hi, On Tue, Sep 25 2018, Jakub Jelinek wrote: > On Mon, Sep 24, 2018 at 08:40:13PM +0200, Martin Jambor wrote: >> 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? > > Isn't that bail out too early? > I mean most of the warnings that are emitted by the function don't really > need TYPE_ARG_TYPES, only the last one does, so can't you just bail out > before the last warning? my reasoning was that if the function is not what I expect it to be, it is better not to touch it. On the other hand, I have no problems moving this test lower as done in the patch below. > Also, the function comment has "gracely", did you mean "gracefully"? Of course I did, thanks for spotting that. Bootstrapped and tested on x86_64-linux and aarch64-linux. OK for trunk? Thanks, Martin 2018-09-25 Martin Jambor PR c/87347 c/ * c-parser.c (warn_for_abs): Bail out if TYPE_ARG_TYPES is NULL. Fix the function comment. testsuite/ * gcc.dg/pr87347.c: New test. --- gcc/c/c-parser.c | 7 +++++-- gcc/testsuite/gcc.dg/pr87347.c | 6 ++++++ 2 files changed, 11 insertions(+), 2 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..1f173fc10e2 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -9102,8 +9102,8 @@ sizeof_ptr_memacc_comptypes (tree type1, tree type2) } /* Warn for patterns where abs-like function appears to be used incorrectly, - gracely ignore any non-abs-like function. The warning location should be - LOC. FNDECL is the declaration of called function, it must be a + gracefully ignore any non-abs-like function. The warning location should + be LOC. FNDECL is the declaration of called function, it must be a BUILT_IN_NORMAL function. ARG is the first and only argument of the call. */ @@ -9223,6 +9223,9 @@ warn_for_abs (location_t loc, tree fndecl, tree arg) return; } + if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl))) + return; + tree ftype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); if (TREE_CODE (atype) == COMPLEX_TYPE) { 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); } -- 2.18.0