From patchwork Wed Aug 25 10:51:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 62669 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]) by ozlabs.org (Postfix) with SMTP id D7E32B70DD for ; Wed, 25 Aug 2010 20:51:32 +1000 (EST) Received: (qmail 25433 invoked by alias); 25 Aug 2010 10:51:30 -0000 Received: (qmail 25416 invoked by uid 22791); 25 Aug 2010 10:51:29 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Aug 2010 10:51:25 +0000 Received: (qmail 28723 invoked from network); 25 Aug 2010 10:51:23 -0000 Received: from unknown (HELO ?84.152.210.217?) (bernds@127.0.0.2) by mail.codesourcery.com with ESMTPA; 25 Aug 2010 10:51:23 -0000 Message-ID: <4C74F5B8.40700@codesourcery.com> Date: Wed, 25 Aug 2010 12:51:36 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100724 Thunderbird/3.1.1 MIME-Version: 1.0 To: GCC Patches Subject: genautomata fix 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 This fixes a problem I found in genautomata while working on a new port. If you have extra parentheses in a regexp, e.g. "(s1)+s1w", we construct a copy of the string "r1" in alloca'd memory on the stack. Later, a pointer to that can escape because when there's only one element in a string, we use the original string rather than the copy we made on an obstack. The extra parentheses are there because the scheduling description is semi-generated and the input expression can expand to "(s1+x1)+s1w" in other cases. Fixed with this patch. Bootstrapped and regression tested on i686-linux. Ok? Bernd * genautomata.c (gen_regexp_repeat, gen_regexp_allof, gen_regexp_oneof, gen_regexp_sequence): Use the string found in vector element 0 rather than the original string when there's only one element. (gen_regexp): Remove extra semicolon. Index: genautomata.c =================================================================== --- genautomata.c (revision 296735) +++ genautomata.c (working copy) @@ -1603,7 +1603,7 @@ gen_regexp_repeat (const char *str) return regexp; } else - return gen_regexp_el (str); + return gen_regexp_el (repeat_vect[0]); } /* Parse reservation STR which possibly contains separator '+'. */ @@ -1629,7 +1629,7 @@ gen_regexp_allof (const char *str) return allof; } else - return gen_regexp_repeat (str); + return gen_regexp_repeat (allof_vect[0]); } /* Parse reservation STR which possibly contains separator '|'. */ @@ -1655,7 +1655,7 @@ gen_regexp_oneof (const char *str) return oneof; } else - return gen_regexp_allof (str); + return gen_regexp_allof (oneof_vect[0]); } /* Parse reservation STR which possibly contains separator ','. */ @@ -1680,7 +1680,7 @@ gen_regexp_sequence (const char *str) return sequence; } else - return gen_regexp_oneof (str); + return gen_regexp_oneof (sequence_vect[0]); } /* Parse construction reservation STR. */ @@ -1688,7 +1688,7 @@ static regexp_t gen_regexp (const char *str) { reserv_str = str; - return gen_regexp_sequence (str);; + return gen_regexp_sequence (str); } /* Process a DEFINE_RESERVATION.