From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11488 invoked by alias); 1 Sep 2011 21:49:45 -0000 Received: (qmail 11478 invoked by uid 22791); 1 Sep 2011 21:49:43 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ns.intrepid.com (HELO mail.intrepid.com) (74.95.8.113) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Sep 2011 21:49:28 +0000 Received: from screamer.local (screamer.local [10.10.1.2]) by mail.intrepid.com (8.13.8/8.13.8) with ESMTP id p81LnOIb007139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Sep 2011 14:49:24 -0700 Received: from screamer.local (screamer.local [127.0.0.1]) by screamer.local (8.14.4/8.14.4) with ESMTP id p81LnORa007977; Thu, 1 Sep 2011 14:49:24 -0700 Received: (from gary@localhost) by screamer.local (8.14.4/8.14.4/Submit) id p81LnOcv007976; Thu, 1 Sep 2011 14:49:24 -0700 Date: Thu, 01 Sep 2011 21:49:00 -0000 From: Gary Funck To: "Joseph S. Myers" Cc: Gcc Patches Subject: [Patch, C] options generation and language count Message-ID: <20110901214924.GA7377@intrepid.com> References: <20110829234640.GB26527@intrepid.com> <20110830160649.GM31092@intrepid.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9amGYk9869ThD9tj" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2011-09/txt/msg00092.txt.bz2 --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 896 2011-09-01 Gary Funck * opts.c (print_specific_help): Fix off-by-one compare in assertion check. * opts.h (CL_PARAMS, CL_WARNING, CL_OPTIMIZATION, CL_DRIVER, CL_TARGET, CL_COMMON, CL_JOINED, CL_SEPARATE, CL_UNDOCUMENTED): Increase by +5 to allow for more languages. * Makefile.in (options.c): Extract max. number of languages value from opts.h, and pass to optc-gen.awk script. * optc-gen.awk: Use max_lang value and issue error if number of languages exceeds implementation-defined limit. This patch extracts the shift count used in the definition of CL_PARAMS to determine the maximum number of language supported by the implementation. optc-gen.awk implements the check and will exit with an error if the number of languages exceeds the limit. Patch, attached. Please review. Thanks, - Gary --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="optc-gen-lang-check.patch" Content-length: 5208 Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 178389) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,15 @@ +2011-09-01 Gary Funck + + * opts.c (print_specific_help): Fix off-by-one compare in + assertion check. + * opts.h (CL_PARAMS, CL_WARNING, CL_OPTIMIZATION, CL_DRIVER, + CL_TARGET, CL_COMMON, CL_JOINED, CL_SEPARATE, CL_UNDOCUMENTED): + Increase by +5 to allow for more languages. + * Makefile.in (options.c): Extract max. number of languages value + from opts.h, and pass to optc-gen.awk script. + * optc-gen.awk: Use max_lang value and issue error if number of + languages exceeds implementation-defined limit. + 2011-08-31 Richard Sandiford * config/i386/i386.md: Use (match_test ...) for attribute tests. Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 178389) +++ gcc/opts.c (working copy) @@ -1125,7 +1125,7 @@ print_specific_help (unsigned int includ /* Sanity check: Make sure that we do not have more languages than we have bits available to enumerate them. */ - gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS); + gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS); /* If we have not done so already, obtain the desired maximum width of the output. */ Index: gcc/opts.h =================================================================== --- gcc/opts.h (revision 178389) +++ gcc/opts.h (working copy) @@ -127,12 +127,12 @@ extern const unsigned int cl_options_cou extern const char *const lang_names[]; extern const unsigned int cl_lang_count; -#define CL_PARAMS (1U << 11) /* Fake entry. Used to display --param info with --help. */ -#define CL_WARNING (1U << 12) /* Enables an (optional) warning message. */ -#define CL_OPTIMIZATION (1U << 13) /* Enables an (optional) optimization. */ -#define CL_DRIVER (1U << 14) /* Driver option. */ -#define CL_TARGET (1U << 15) /* Target-specific option. */ -#define CL_COMMON (1U << 16) /* Language-independent. */ +#define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */ +#define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */ +#define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */ +#define CL_DRIVER (1U << 19) /* Driver option. */ +#define CL_TARGET (1U << 20) /* Target-specific option. */ +#define CL_COMMON (1U << 21) /* Language-independent. */ #define CL_MIN_OPTION_CLASS CL_PARAMS #define CL_MAX_OPTION_CLASS CL_COMMON @@ -142,9 +142,9 @@ extern const unsigned int cl_lang_count; This distinction is important because --help will not list options which only have these higher bits set. */ -#define CL_JOINED (1U << 17) /* If takes joined argument. */ -#define CL_SEPARATE (1U << 18) /* If takes a separate argument. */ -#define CL_UNDOCUMENTED (1U << 19) /* Do not output with --help. */ +#define CL_JOINED (1U << 22) /* If takes joined argument. */ +#define CL_SEPARATE (1U << 23) /* If takes a separate argument. */ +#define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */ /* Flags for an enumerated option argument. */ #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */ Index: gcc/optc-gen.awk =================================================================== --- gcc/optc-gen.awk (revision 178389) +++ gcc/optc-gen.awk (working copy) @@ -30,6 +30,15 @@ # Dump that array of options into a C file. END { +# MAX_LANG is the maximum number of languages that can be defined. +# Its value is extracted from the value of CL_PARAMS in opts.h +# and is passed on the command line as '-v max_lang=...'. +if (n_langs > max_lang) { + print "Error: the number of defined languages (" n_langs ") " \ + "exceeds the maximum supported by this implementation " \ + "(" max_lang ")" > "/dev/stderr" + exit 2 +} print "/* This file is auto-generated by optc-gen.awk. */" print "" n_headers = split(header_name, headers, " ") Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 178389) +++ gcc/Makefile.in (working copy) @@ -2216,10 +2216,18 @@ s-options: $(ALL_OPT_FILES) Makefile $(s $(STAMP) s-options options.c: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \ - $(srcdir)/optc-gen.awk + $(srcdir)/optc-gen.awk $(srcdir)/opts.h + max_lang=`$(AWK) '/^#define +CL_PARAMS +\(1U +<< +[0-9]+\)/ \ + {x=$$5; sub(")","",x); print +x; exit}' $(srcdir)/opts.h`; \ + if test -z "$${max_lang}"; then \ + echo "Could not find a valid CL_PARAMS definition in $(srcdir)/opts.h"; \ + exit 2; \ + fi; \ $(AWK) -f $(srcdir)/opt-functions.awk -f $(srcdir)/opt-read.awk \ -f $(srcdir)/optc-gen.awk \ - -v header_name="config.h system.h coretypes.h tm.h" < $< > $@ + -v max_lang="$$max_lang" \ + -v header_name="config.h system.h coretypes.h tm.h" < $< > $@.tmp + mv $@.tmp $@ options-save.c: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \ $(srcdir)/optc-save-gen.awk --9amGYk9869ThD9tj--