Make option flags consistently unsigned

Joseph S. Myers joseph@codesourcery.com
Tue Mar 29 22:16:00 GMT 2011


This patch makes variables, fields, parameters and macros used for
command-line option flags consistently unsigned.  In most places they
were already unsigned, but the CL_* values themselves were signed and
some other places used signed int for flags.

As noted in <http://gcc.gnu.org/ml/gcc-patches/2010-11/msg00479.html>
this makes bit 31 available for use for another flag (1U << 31 is more
appropriate than 1 << 31, which is not defined in ISO C).  It is
logically right for such a collection of flags to be unsigned, but it
will be necessary soon to follow up by splitting this field.  (I have
two uses of flag bits I expect to add soon: one to say that an
option's argument is case-insensitive, one to indicate that an option
is an alias for the negative form of another option.)

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
to mainline.

2011-03-29  Joseph Myers  <joseph@codesourcery.com>

	* lto-opts.c (register_user_option_p, lto_register_user_option):
	Make type argument unsigned.
	* lto-streamer.h (lto_register_user_option): Make type argument
	unsigned.
	* opth-gen.awk: Make CL_* macros unsigned.
	* opts-common.c (find_opt): Make lang_mask argument unsigned.
	* opts.h (CL_PARAMS, CL_WARNING, CL_OPTIMIZATION, CL_DRIVER,
	CL_TARGET, CL_COMMON, CL_SEPARATE_NARGS_MASK, CL_SEPARATE_ALIAS,
	CL_NO_DRIVER_ARG, CL_REJECT_DRIVER, CL_SAVE, CL_DISABLED,
	CL_REPORT, CL_JOINED, CL_SEPARATE, CL_REJECT_NEGATIVE,
	CL_MISSING_OK, CL_UINTEGER, CL_UNDOCUMENTED): Make unsigned.
	(find_opt): Make lang_mask argument unsigned.

Index: opts-common.c
===================================================================
--- opts-common.c	(revision 171675)
+++ opts-common.c	(working copy)
@@ -1,5 +1,5 @@
 /* Command line option handling.
-   Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -52,7 +52,7 @@ static void prune_options (struct cl_dec
    front end, the longest match for a different front end is returned
    (or N_OPTS if none) and the caller emits an error message.  */
 size_t
-find_opt (const char *input, int lang_mask)
+find_opt (const char *input, unsigned int lang_mask)
 {
   size_t mn, mn_orig, mx, md, opt_len;
   size_t match_wrong_lang;
Index: opts.h
===================================================================
--- opts.h	(revision 171675)
+++ opts.h	(working copy)
@@ -1,5 +1,5 @@
 /* Command line option handling.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -83,12 +83,12 @@ extern const unsigned int cl_options_cou
 extern const char *const lang_names[];
 extern const unsigned int cl_lang_count;
 
-#define CL_PARAMS               (1 << 11) /* Fake entry.  Used to display --param info with --help.  */
-#define CL_WARNING		(1 << 12) /* Enables an (optional) warning message.  */
-#define CL_OPTIMIZATION		(1 << 13) /* Enables an (optional) optimization.  */
-#define CL_DRIVER		(1 << 14) /* Driver option.  */
-#define CL_TARGET		(1 << 15) /* Target-specific option.  */
-#define CL_COMMON		(1 << 16) /* Language-independent.  */
+#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_MIN_OPTION_CLASS	CL_PARAMS
 #define CL_MAX_OPTION_CLASS	CL_COMMON
@@ -101,20 +101,20 @@ extern const unsigned int cl_lang_count;
 /* Options marked with CL_SEPARATE take a number of separate arguments
    (1 to 4) that is one more than the number in this bit-field.  */
 #define CL_SEPARATE_NARGS_SHIFT	17
-#define CL_SEPARATE_NARGS_MASK	(3 << CL_SEPARATE_NARGS_SHIFT)
+#define CL_SEPARATE_NARGS_MASK	(3U << CL_SEPARATE_NARGS_SHIFT)
 
-#define CL_SEPARATE_ALIAS	(1 << 19) /* Option is an alias when used with separate argument.  */
-#define CL_NO_DRIVER_ARG	(1 << 20) /* Option takes no argument in the driver.  */
-#define CL_REJECT_DRIVER	(1 << 21) /* Reject this option in the driver.  */
-#define CL_SAVE			(1 << 22) /* Target-specific option for attribute.  */
-#define CL_DISABLED		(1 << 23) /* Disabled in this configuration.  */
-#define CL_REPORT		(1 << 24) /* Report argument with -fverbose-asm  */
-#define CL_JOINED		(1 << 25) /* If takes joined argument.  */
-#define CL_SEPARATE		(1 << 26) /* If takes a separate argument.  */
-#define CL_REJECT_NEGATIVE	(1 << 27) /* Reject no- form.  */
-#define CL_MISSING_OK		(1 << 28) /* Missing argument OK (joined).  */
-#define CL_UINTEGER		(1 << 29) /* Argument is an integer >=0.  */
-#define CL_UNDOCUMENTED		(1 << 30) /* Do not output with --help.  */
+#define CL_SEPARATE_ALIAS	(1U << 19) /* Option is an alias when used with separate argument.  */
+#define CL_NO_DRIVER_ARG	(1U << 20) /* Option takes no argument in the driver.  */
+#define CL_REJECT_DRIVER	(1U << 21) /* Reject this option in the driver.  */
+#define CL_SAVE			(1U << 22) /* Target-specific option for attribute.  */
+#define CL_DISABLED		(1U << 23) /* Disabled in this configuration.  */
+#define CL_REPORT		(1U << 24) /* Report argument with -fverbose-asm  */
+#define CL_JOINED		(1U << 25) /* If takes joined argument.  */
+#define CL_SEPARATE		(1U << 26) /* If takes a separate argument.  */
+#define CL_REJECT_NEGATIVE	(1U << 27) /* Reject no- form.  */
+#define CL_MISSING_OK		(1U << 28) /* Missing argument OK (joined).  */
+#define CL_UINTEGER		(1U << 29) /* Argument is an integer >=0.  */
+#define CL_UNDOCUMENTED		(1U << 30) /* Do not output with --help.  */
 
 /* Flags for an enumerated option argument.  */
 #define CL_ENUM_CANONICAL	(1 << 0) /* Canonical for this value.  */
@@ -280,7 +280,7 @@ extern const char **in_fnames;
 
 extern unsigned num_in_fnames;
 
-size_t find_opt (const char *input, int lang_mask);
+size_t find_opt (const char *input, unsigned int lang_mask);
 extern int integral_argument (const char *arg);
 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
 			       const char **argp, int value,
Index: opth-gen.awk
===================================================================
--- opth-gen.awk	(revision 171675)
+++ opth-gen.awk	(working copy)
@@ -451,9 +451,9 @@ for (i = 0; i < n_langs; i++) {
 	macros[i] = "CL_" langs[i]
 	gsub( "[^" alnum "_]", "X", macros[i] )
 	s = substr("            ", length (macros[i]))
-	print "#define " macros[i] s " (1 << " i ")"
+	print "#define " macros[i] s " (1U << " i ")"
     }
-print "#define CL_LANG_ALL   ((1 << " n_langs ") - 1)"
+print "#define CL_LANG_ALL   ((1U << " n_langs ") - 1)"
 
 print ""
 print "enum opt_code"
Index: lto-opts.c
===================================================================
--- lto-opts.c	(revision 171675)
+++ lto-opts.c	(working copy)
@@ -194,7 +194,7 @@ input_string_block (struct lto_input_blo
    Among others, optimization options may well be appropriate here.  */
 
 static bool
-register_user_option_p (size_t code, int type)
+register_user_option_p (size_t code, unsigned int type)
 {
   if (type == CL_TARGET)
     return true;
@@ -215,7 +215,8 @@ register_user_option_p (size_t code, int
    If relevant to LTO, save it in the user options vector.  */
 
 void
-lto_register_user_option (size_t code, const char *arg, int value, int type)
+lto_register_user_option (size_t code, const char *arg, int value,
+			  unsigned int type)
 {
   if (register_user_option_p (code, type))
     {
Index: lto-streamer.h
===================================================================
--- lto-streamer.h	(revision 171675)
+++ lto-streamer.h	(working copy)
@@ -1,7 +1,7 @@
 /* Data structures and declarations used for reading and writing
    GIMPLE to a file stream.
 
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
    Contributed by Doug Kwan <dougkwan@google.com>
 
 This file is part of GCC.
@@ -933,7 +933,7 @@ extern GTY(()) VEC(tree,gc) *lto_global_
 
 
 /* In lto-opts.c.  */
-extern void lto_register_user_option (size_t, const char *, int, int);
+extern void lto_register_user_option (size_t, const char *, int, unsigned int);
 extern void lto_read_file_options (struct lto_file_decl_data *);
 extern void lto_write_options (void);
 extern void lto_reissue_options (void);

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Gcc-patches mailing list