From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 38EC03858C27 for ; Mon, 19 Jul 2021 20:40:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38EC03858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 16JKd73n016267; Mon, 19 Jul 2021 15:39:07 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 16JKd6W9016264; Mon, 19 Jul 2021 15:39:06 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 19 Jul 2021 15:39:06 -0500 From: Segher Boessenkool To: Bill Schmidt Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH 11/55] rs6000: Parsing built-in input file, part 1 of 3 Message-ID: <20210719203906.GQ1583@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_NUMSUBJECT, TXREP, T_SPF_HELO_PERMERROR, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2021 20:40:09 -0000 Hi! On Thu, Jun 17, 2021 at 10:18:55AM -0500, Bill Schmidt wrote: > +enum bif_stanza > +{ ... > + NUMBIFSTANZAS > +}; Doing "NUM" things like this makes it valid to assign the NUM value to a variable of this enum type, and importantly, the compiler cannot warn for it then. So this is a bit of an antipattern. > +/* Attributes of a builtin function. */ > +struct attrinfo > +{ > + char isinit; > + char isset; [snip] Is it nicer to have "bool" for these? > +static int *bif_order; This one probably can use a comment. > +static bif_stanza > +stanza_name_to_stanza (const char *stanza_name) > +{ > + for (int i = 0; i < NUMBIFSTANZAS; i++) > + if (!strcmp (stanza_name, stanza_map[i].stanza_name)) > + return stanza_map[i].stanza; > + assert (false); > +} assert() compiles to nothing if NDEBUG is defined at the point you include the header. That shouldn't happen, but please just make a fatal() or similar function for this? > + /* Append a number representing the order in which this function > + was encountered to its name, and save in another lookup > + structure. */ > + int orig_len = strlen (bifs[curr_bif].idname); > + char *buf = (char *) malloc (orig_len + 7); > + strcpy (buf, bifs[curr_bif].idname); > + buf[orig_len] = ':'; > + char numstr[6]; > + sprintf (numstr, "%05d", curr_bif); > + strcpy (&buf[orig_len + 1], numstr); char *buf; asprintf (&buf, "%s:%05d", bifs[curr_bif].idname, curr_bif); > +#ifdef DEBUG > + (*diag) ("pattern name is '%s'.\n", bifs[curr_bif].patname); > +#endif Maybe you can do the DEBUG thing inside the diag function itself, so that you do not need the macro check at every use? Or use a different function, even. (That has nothing to do with this patch in particular of course). Okay for trunk. Thanks! Segher