From patchwork Fri Jun 7 13:12:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 249715 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 77EE92C008F for ; Fri, 7 Jun 2013 23:13:16 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=t4AElhoLIvWxMIUJL2z020Y4e2CoYA0aXws28p9JgKz K5QNPlUE1qgVXf/iHpNsPajBtPGQWGOki4P5oXaMtRs5oCfKwS93VjzZYKjsHMxD prAF9ieOaMFtcIgO8EvxB28dEw1oiykDlvy8oTdX7H8TrNzjgywcjtuJwA+aXyLg = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=eKjlbM3y7CEB1m4Oh/O5i7ObtRY=; b=Bk8f+O967cJNyXy0/ 6hBa0FOpvzRLFiCHALK2mUUloUaY5U8H7FFljzEf/rJU09Z9v90hPii/+CMvHn/8 WWtd/+UbMs/jLPBS31amJyku5jz+31LS9QI2MFAEWmfLMxPSH4ysoTRUnyQPSkxp vxA+5NP29oaGfQqUzDn37S9xts= Received: (qmail 24672 invoked by alias); 7 Jun 2013 13:13:10 -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 24662 invoked by uid 89); 7 Jun 2013 13:13:09 -0000 X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL autolearn=ham version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 07 Jun 2013 13:13:09 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1UkwTa-0000Pq-Qe from Tom_deVries@mentor.com ; Fri, 07 Jun 2013 06:13:06 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 7 Jun 2013 06:13:06 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Fri, 7 Jun 2013 14:13:01 +0100 Message-ID: <51B1DC52.9000604@mentor.com> Date: Fri, 7 Jun 2013 15:12:50 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: Vladimir Makarov CC: "gcc-patches@gcc.gnu.org" Subject: Add error message for mismatched parentheses in reservation string X-Virus-Found: No Vladimir, If I introduce an unbalanced parentheses error in a reservation string, f.i. in athlon.md using the following patch: ... and rebuild cc1, I get a segmentation fault: ... build/genautomata gcc/config/i386/i386.md \ insn-conditions.md > tmp-automata.c /bin/bash: line 1: 18077 Segmentation fault (core dumped) build/genautomata gcc/config/i386/i386.md insn-conditions.md > tmp-automata.c make: *** [s-automata] Error 139 ... The segmentation fault happens because sequence_vect is set to NULL here in gen_regexp_sequence in genautomata.c: ... sequence_vect = get_str_vect (str, &els_num, ',', TRUE); if (els_num > 1) ... and sequence_vect is dereferenced here: ... else return gen_regexp_oneof (sequence_vect[0]); ... The patch adds error checking for the specific case of unbalanced parentheses, and for sequence_vect == NULL in general. Using the patch the error message becomes: ... genautomata: unbalanced parentheses in reservation `(athlon-decode2, athlon-decode0) | (nothing,(athlon-decode0 + athlon-decode1)) | (nothing,(athlon-decode1 + athlon-decode2)))' ... Tested by completing a non-bootstrap build. OK for trunk? Thanks, - Tom 2013-06-07 Tom de Vries * genautomata.c (gen_regexp_sequence): Handle els_num == -1. Handle sequence_vect == NULL. diff --git a/gcc/genautomata.c b/gcc/genautomata.c index 3665d95..add4624 100644 --- a/gcc/genautomata.c +++ b/gcc/genautomata.c @@ -1672,6 +1672,10 @@ gen_regexp_sequence (const char *str) int i; sequence_vect = get_str_vect (str, &els_num, ',', TRUE); + if (els_num == -1) + fatal ("unbalanced parentheses in reservation `%s'", str); + if (sequence_vect == NULL) + fatal ("invalid reservation `%s'", str); if (els_num > 1) { sequence = XCREATENODEVAR (struct regexp, sizeof (struct regexp)