From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12142 invoked by alias); 24 Jan 2014 16:09:52 -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 12129 invoked by uid 89); 24 Jan 2014 16:09:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 ESMTP; Fri, 24 Jan 2014 16:09:45 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0OG9isR025698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 24 Jan 2014 11:09:44 -0500 Received: from localhost (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0OG9V1b021998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 24 Jan 2014 11:09:35 -0500 Received: by localhost (Postfix, from userid 1000) id B28801632DD; Fri, 24 Jan 2014 17:09:29 +0100 (CET) From: Dodji Seketeli To: Jakub Jelinek Cc: Markus Trippelsdorf , Bernd Edlinger , GCC Patches , Tom Tromey , Manuel =?utf-8?B?TMOzcGV6LUliw6HDsWV6?= Subject: Re: [PATCH] preprocessor/58580 - preprocessor goes OOM with warning for zero literals References: <87zjpbb5qu.fsf@redhat.com> <20131111142159.GZ27813@tucnak.zalov.cz> <878uwuap4f.fsf@redhat.com> <878uwt63e2.fsf@redhat.com> <20131113081610.GH27813@tucnak.zalov.cz> <87zjp7t73c.fsf@redhat.com> <87vbxcig8t.fsf@redhat.com> <20140124150532.GB396@x4> <87iot9qtff.fsf@redhat.com> <20140124154419.GQ892@tucnak.redhat.com> X-URL: http://www.redhat.com Date: Fri, 24 Jan 2014 16:09:00 -0000 In-Reply-To: <20140124154419.GQ892@tucnak.redhat.com> (Jakub Jelinek's message of "Fri, 24 Jan 2014 16:44:19 +0100") Message-ID: <878uu5qs3q.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2014-01/txt/msg01592.txt.bz2 Jakub Jelinek writes: > On Fri, Jan 24, 2014 at 04:40:52PM +0100, Dodji Seketeli wrote: >> > The patch causes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59935 . >> > The follow-up patch (fp == NULL check) doesn't help. >> >> I am looking into that, sorry for the inconvenience. > > I'd say we want something like following. Note that while the c == NULL > bailout would be usually sufficient, if you'll do: > echo foobar > '' > it would still crash. Line 0 is used only for the special locations > (command line, built-in macros) and there is no file associated with it > anyway. > > --- gcc/input.c.jj 2014-01-24 16:32:34.000000000 +0100 > +++ gcc/input.c 2014-01-24 16:41:42.012671452 +0100 > @@ -698,7 +698,13 @@ location_get_source_line (expanded_locat > static char *buffer; > static ssize_t len; > > - fcache * c = lookup_or_add_file_to_cache_tab (xloc.file); > + if (xloc.line == 0) > + return NULL; > + > + fcache *c = lookup_or_add_file_to_cache_tab (xloc.file); > + if (c == NULL) > + return NULL; > + > bool read = read_line_num (c, xloc.line, &buffer, &len); > > if (read && line_len) Indeed. Though, I am testing the patch below that makes read_line_num gracefully handle empty caches or zero locations. The rest of the code should just work with that as is. * input.c (read_line_num): Gracefully handle non-file locations or empty caches. diff --git a/gcc/input.c b/gcc/input.c index 547c177..b05e1da 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -600,7 +600,8 @@ static bool read_line_num (fcache *c, size_t line_num, char ** line, ssize_t *line_len) { - gcc_assert (line_num > 0); + if (!c || line_num < 1) + return false; if (line_num <= c->line_num) { diff --git a/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c new file mode 100644 index 0000000..04a06b2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/warning-zero-location.c @@ -0,0 +1,6 @@ +/* + { dg-options "-D _GNU_SOURCE" } + { dg-do compile } + */ + +#define _GNU_SOURCE /* { dg-warning "redefined" } */ -- Dodji