From patchwork Tue Jul 29 00:14:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 374332 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9BAF91400B2 for ; Tue, 29 Jul 2014 10:15:07 +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:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=nH4MICIWacalKcNMxVkXrGox1z/DHgenx5nLWD+gtE4 U2OBcFys9in41ydV0PWjQAfUWjfHT5PcdBXjoAlL3OT1zStSnKkyxkG/XXB1ZbQ/ Mp6xQFcGmC+Y3U3P3dMTRt8IDFVchpCDmcdMVqKZByTV6ggWW5FCScgvDsHIGGjo = 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:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=WuncKfPP3KuI6MhpfD8muu6q70k=; b=AI8iKXbjp3RvANX8R Hq9bZ+IutLcLb0rw5vbRHy02KMvoQP2G29GkxRrceCG+0XA5vzkleigtKZxDAQ3l 7p3lRqe2mHXbYLACUVV9WXpmkAp7Lp7AIl8VillT5vGpom/tQHdAD+tb7P/MNueH 5FCDOqSok3+9zYv4cPX0DUsKmE= Received: (qmail 10564 invoked by alias); 29 Jul 2014 00:14:59 -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 10533 invoked by uid 89); 29 Jul 2014 00:14:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Jul 2014 00:14:56 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 28 Jul 2014 17:14:54 -0700 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.145]) by fmsmga002.fm.intel.com with ESMTP; 28 Jul 2014 17:14:54 -0700 Received: by gnu-6.sc.intel.com (Postfix, from userid 1000) id 1408720124C; Mon, 28 Jul 2014 17:14:54 -0700 (PDT) Date: Mon, 28 Jul 2014 17:14:54 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: PATCH: PR bootstrap/61914: [4.10 Regression] wide-int change breaks bootstrap Message-ID: <20140729001453.GA14203@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) wide-int change introduced C++ templates in header file, like generic_wide_int::precision>> create_user_defined_type in gengtype.c calls 1. strtok (arg, ",>"). 2. resolve_typedef (field_name, pos), which calls create_user_defined_type, which calls strtok (arg, ",>") again. 3. strtok (0, ",>"), which uses the wrong saved pointer. On Linux/x32, I got build/gengtype \ -S /export/gnu/import/git/gcc/gcc -I gtyp-input.list -w tmp-gtype.state /bin/sh /export/gnu/import/git/gcc/gcc/../move-if-change tmp-gtype.state gtype.state build/gengtype \ -r gtype.state gengtype: gtype.state:22372: Invalid state file; Lexical error... make: *** [s-gtype] Error 1 [hjl@gnu-mic-2 gcc]$ grep xfff gtype.state (!type undefined 1481 nil gc_unused "qQ\x02\xffffff98\x01" (!pair "qQ\x02\xffffff98\x01" (!type undefined 1486 nil gc_unused "qQ\x02\xffffff87\x01" (!pair "qQ\x02\xffffff87\x01" (!pair "qQ\x02\xffffff98\x01" (!pair "qQ\x02\xffffff87\x01" [hjl@gnu-mic-2 gcc]$ It is a pure luck that it doesn't fail on other platforms. This patch replaces strtok with strtoken. OK for trunk after bootstrap + testsuite? H.J. --- 2014-07-28 H.J. Lu PR bootstrap/61914 * gengtype.c (strtoken): New function. (create_user_defined_type): Replace strtok with strtoken. diff --git a/gcc/gengtype.c b/gcc/gengtype.c index ffe3f94..e66941b 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -569,6 +569,40 @@ do_scalar_typedef (const char *s, struct fileloc *pos) do_typedef (s, &scalar_nonchar, pos); } +/* Similar to strtok_r. */ + +static char * +strtoken (char *str, const char *delim, char **next) +{ + char *p; + + if (str == NULL) + str = *next; + + /* Skip the leading delimiters. */ + str += strspn (str, delim); + if (*str == '\0') + /* This is an empty token. */ + return NULL; + + /* The current token. */ + p = str; + + /* Find the next delimiter. */ + str += strcspn (str, delim); + if (*str == '\0') + /* This is the last token. */ + *next = str; + else + { + /* Terminate the current token. */ + *str = '\0'; + /* Advance to the next token. */ + *next = str + 1; + } + + return p; +} /* Define TYPE_NAME to be a user defined type at location POS. */ @@ -599,7 +633,8 @@ create_user_defined_type (const char *type_name, struct fileloc *pos) comma-separated list of strings, implicitly assumed to be type names, potentially with "*" characters. */ char *arg = open_bracket + 1; - char *type_id = strtok (arg, ",>"); + char *next; + char *type_id = strtoken (arg, ",>", &next); pair_p fields = 0; while (type_id) { @@ -628,7 +663,7 @@ create_user_defined_type (const char *type_name, struct fileloc *pos) arg_type = resolve_typedef (field_name, pos); fields = create_field_at (fields, arg_type, field_name, 0, pos); - type_id = strtok (0, ",>"); + type_id = strtoken (0, ",>", &next); } /* Associate the field list to TY. */