This is the hand-written half of the patch series. gcc/ada/gcc-interface/misc.c requires some special care: it "undeffed" some options macros in order to support explicit variables for 5 options, whilst using other options via macros. I ported this file by hand, disabling the refactoring script for this specific file. These 5 variables continue to exist as variables in the new implementation.
gcc/ * opth-gen.awk: Introduce GCC_OPTION macro, using it to eliminate the family of macros named after options that implicitly looked up within the global_options global in favor of explicit lookup. gcc/ada/ * gcc-interface/gigi.h (flag_vms_malloc64): This macro exists on non-VMS systems, to provide a value for this flag, which exists as an option, but only on VMS, within vms.opt. Given that we can't redefine a direct GCC_OPTION (flag_vms_malloc64) lookup, instead rename this to... (GCC_OPTION_flag_vms_malloc64): New macro: an option lookup on VMS, 0 elsewhere. * gcc-interface/decl.c (gnat_to_gnu_param): Use new macro GCC_OPTION_flag_vms_malloc64 in place of flag_vms_malloc64. * gcc-interface/misc.c (gnat_handle_option): Manually wrap option usage in GCC_OPTION macro. (optimize): Remove undef of macro. (optimize_size): Likewise. (flag_compare_debug): Likewise. (flag_short_enums): Likewise. (flag_stack_check): Likewise. (gnat_post_options): Wrap some option usage in GCC_OPTION macro, avoiding wrapping the variables introduced for the specific options that formerly had undefs above. (gnat_init): Wrap option usage in GCC_OPTION macro. (gnat_init_gcc_eh): Likewise. (gnat_init_gcc_fp): Likewise. gcc/c-family/ * c.opt (Wformat-contains-nul): Wrap usage of "warn_format" within GCC_OPTION macro, and wrap all of body of LangEnabledBy in curly braces so that the awk opt parser can cope with the parentheses. (Wformat-extra-args): Likewise. (Wformat-nonliteral): Likewise. (Wformat-security): Likewise. (Wformat-y2k): Likewise. (Wformat-zero-length): Likewise. (Wnonnull): Likewise. --- gcc/ada/gcc-interface/decl.c | 3 ++- gcc/ada/gcc-interface/gigi.h | 6 ++++-- gcc/ada/gcc-interface/misc.c | 31 +++++++++++++------------------ gcc/c-family/c.opt | 14 +++++++------- gcc/config/alpha/vms.h | 2 +- gcc/opth-gen.awk | 15 ++++++++------- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 4180e59..4c9788d 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -5752,7 +5752,8 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech, /* VMS descriptors are themselves passed by reference. */ if (mech == By_Short_Descriptor || - (mech == By_Descriptor && TARGET_ABI_OPEN_VMS && !flag_vms_malloc64)) + (mech == By_Descriptor && TARGET_ABI_OPEN_VMS + && !GCC_OPTION_flag_vms_malloc64)) gnu_param_type = build_pointer_type (build_vms_descriptor32 (gnu_param_type, Mechanism (gnat_param), diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index b709273..a565dc6 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -1059,8 +1059,10 @@ extern void enumerate_modes (void (*f) (const char *, int, int, int, int, int, /* VMS option set by default, when clear forces 32bit mallocs and 32bit Descriptors. Always used in combination with TARGET_ABI_OPEN_VMS so no effect on non-VMS systems. */ -#if TARGET_ABI_OPEN_VMS == 0 -#define flag_vms_malloc64 0 +#if TARGET_ABI_OPEN_VMS +#define GCC_OPTION_flag_vms_malloc64 flag_vms_malloc64 +#else +#define GCC_OPTION_flag_vms_malloc64 0 #endif /* Convenient shortcuts. */ diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index a5f2881..e447095 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -133,8 +133,8 @@ gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value, OPT_Wunused, NULL, value, gnat_option_lang_mask (), kind, loc, handlers, global_dc); - warn_uninitialized = value; - warn_maybe_uninitialized = value; + GCC_OPTION (warn_uninitialized) = value; + GCC_OPTION (warn_maybe_uninitialized) = value; break; case OPT_gant: @@ -225,11 +225,6 @@ gnat_init_options (unsigned int decoded_options_count, /* Ada code requires variables for these settings rather than elements of the global_options structure. */ -#undef optimize -#undef optimize_size -#undef flag_compare_debug -#undef flag_short_enums -#undef flag_stack_check int optimize; int optimize_size; int flag_compare_debug; @@ -244,16 +239,16 @@ static bool gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED) { /* Excess precision other than "fast" requires front-end support. */ - if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD + if (GCC_OPTION (flag_excess_precision_cmdline) == EXCESS_PRECISION_STANDARD && TARGET_FLT_EVAL_METHOD_NON_DEFAULT) sorry ("-fexcess-precision=standard for Ada"); - flag_excess_precision_cmdline = EXCESS_PRECISION_FAST; + GCC_OPTION (flag_excess_precision_cmdline) = EXCESS_PRECISION_FAST; /* ??? The warning machinery is outsmarted by Ada. */ - warn_unused_parameter = 0; + GCC_OPTION (warn_unused_parameter) = 0; /* No psABI change warnings for Ada. */ - warn_psabi = 0; + GCC_OPTION (warn_psabi) = 0; /* No caret by default for Ada. */ if (!global_options_set.x_flag_diagnostics_show_caret) @@ -336,7 +331,7 @@ gnat_init (void) /* Do little here, most of the standard declarations are set up after the front-end has been run. Use the same `char' as C, this doesn't really matter since we'll use the explicit `unsigned char' for Character. */ - build_common_tree_nodes (flag_signed_char, false); + build_common_tree_nodes (GCC_OPTION (flag_signed_char), false); /* In Ada, we use an unsigned 8-bit type for the default boolean type. */ boolean_type_node = make_unsigned_type (8); @@ -388,8 +383,8 @@ gnat_init_gcc_eh (void) marked as "cannot trap" if the flag is not set (see emit_libcall_block). We should not let this be since it is possible for such calls to actually raise in Ada. */ - flag_exceptions = 1; - flag_non_call_exceptions = 1; + GCC_OPTION (flag_exceptions) = 1; + GCC_OPTION (flag_non_call_exceptions) = 1; init_eh (); } @@ -402,18 +397,18 @@ gnat_init_gcc_fp (void) /* Disable FP optimizations that ignore the signedness of zero if S'Signed_Zeros is true, but don't override the user if not. */ if (Signed_Zeros_On_Target) - flag_signed_zeros = 1; + GCC_OPTION (flag_signed_zeros) = 1; else if (!global_options_set.x_flag_signed_zeros) - flag_signed_zeros = 0; + GCC_OPTION (flag_signed_zeros) = 0; /* Assume that FP operations can trap if S'Machine_Overflow is true, but don't override the user if not. ??? Alpha/VMS enables FP traps without declaring it. */ if (Machine_Overflows_On_Target || TARGET_ABI_OPEN_VMS) - flag_trapping_math = 1; + GCC_OPTION (flag_trapping_math) = 1; else if (!global_options_set.x_flag_trapping_math) - flag_trapping_math = 0; + GCC_OPTION (flag_trapping_math) = 0; } /* Print language-specific items in declaration NODE. */ diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 7d0a2cd..21df9a0 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -400,27 +400,27 @@ C ObjC C++ ObjC++ Warning Alias(Wformat=, 1, 0) Warn about printf/scanf/strftime/strfmon format string anomalies Wformat-contains-nul -C ObjC C++ ObjC++ Var(warn_format_contains_nul) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0) +C ObjC C++ ObjC++ Var(warn_format_contains_nul) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=, GCC_OPTION (warn_format) >= 1, 0}) Warn about format strings that contain NUL bytes Wformat-extra-args -C ObjC C++ ObjC++ Var(warn_format_extra_args) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0) +C ObjC C++ ObjC++ Var(warn_format_extra_args) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=, GCC_OPTION (warn_format) >= 1, 0}) Warn if passing too many arguments to a function for its format string Wformat-nonliteral -C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0) +C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=, GCC_OPTION (warn_format) >= 2, 0}) Warn about format strings that are not literals Wformat-security -C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0) +C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=, GCC_OPTION (warn_format) >= 2, 0}) Warn about possible security problems with format functions Wformat-y2k -C ObjC C++ ObjC++ Var(warn_format_y2k) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=,warn_format >= 2, 0) +C ObjC C++ ObjC++ Var(warn_format_y2k) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=,GCC_OPTION (warn_format) >= 2, 0}) Warn about strftime formats yielding 2-digit years Wformat-zero-length -C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=,warn_format >= 1, 0) +C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=,GCC_OPTION (warn_format) >= 1, 0}) Warn about zero-length formats Wformat= @@ -573,7 +573,7 @@ C++ ObjC++ Var(warn_nonvdtor) Warning Warn about non-virtual destructors Wnonnull -C ObjC C++ ObjC++ Var(warn_nonnull) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=,warn_format >= 1,0) +C ObjC C++ ObjC++ Var(warn_nonnull) Warning LangEnabledBy({C ObjC C++ ObjC++,Wformat=,GCC_OPTION (warn_format) >= 1,0}) Warn about NULL being passed to argument slots marked as requiring non-NULL Wnonnull diff --git a/gcc/config/alpha/vms.h b/gcc/config/alpha/vms.h index b297778..df0130c 100644 --- a/gcc/config/alpha/vms.h +++ b/gcc/config/alpha/vms.h @@ -48,7 +48,7 @@ along with GCC; see the file COPYING3. If not see /* The maximum alignment 'malloc' honors. */ #undef MALLOC_ABI_ALIGNMENT #define MALLOC_ABI_ALIGNMENT \ - ((flag_vms_malloc64 && flag_vms_pointer_size != VMS_POINTER_SIZE_NONE \ + ((flag_vms_malloc64 && flag_vms_pointer_size != VMS_POINTER_SIZE_NONE \ ? 16 : 8) * BITS_PER_UNIT) #undef FIXED_REGISTERS diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk index 45aee34..1b96151 100644 --- a/gcc/opth-gen.awk +++ b/gcc/opth-gen.awk @@ -44,14 +44,17 @@ if (n_extra_h_includes > 0) { } print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)" -print "#ifndef GENERATOR_FILE" +print "#ifdef GENERATOR_FILE" +print "#define GCC_OPTION(NAME) (NAME)" +print "#else" print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)" print "struct GTY(()) gcc_options" print "#else" print "struct gcc_options" print "#endif" print "{" -print "#endif" +print "#define GCC_OPTION(NAME) (global_options.x_##NAME)" +print "#endif /* #ifdef GENERATOR_FILE */" for (i = 0; i < n_extra_vars; i++) { var = extra_vars[i] @@ -70,7 +73,6 @@ for (i = 0; i < n_extra_vars; i++) { print "extern " orig_var ";" print "#else" print " " type " x_" name type_after ";" - print "#define " name " global_options.x_" name print "#endif" } @@ -90,7 +92,6 @@ for (i = 0; i < n_opts; i++) { print "extern " var_type(flags[i]) name ";" print "#else" print " " var_type(flags[i]) "x_" name ";" - print "#define " name " global_options.x_" name print "#endif" } for (i = 0; i < n_opts; i++) { @@ -381,7 +382,7 @@ for (i = 0; i < n_opts; i++) { extra_mask_macros[name] = 1 } print "#define TARGET_" name \ - " ((" vname " & " mask name ") != 0)" + " ((GCC_OPTION (" vname ") & " mask name ") != 0)" print "#define TARGET_" name "_P(" vname ")" \ " ((" vname " & " mask name ") != 0)" } @@ -389,7 +390,7 @@ for (i = 0; i < n_opts; i++) { for (i = 0; i < n_extra_masks; i++) { if (extra_mask_macros[extra_masks[i]] == 0) print "#define TARGET_" extra_masks[i] \ - " ((target_flags & MASK_" extra_masks[i] ") != 0)" + " ((GCC_OPTION (target_flags) & MASK_" extra_masks[i] ") != 0)" } print "" @@ -399,7 +400,7 @@ for (i = 0; i < n_opts; i++) { vname = var_name(flags[i]) mask = "OPTION_MASK_" if (vname == "") { - vname = "target_flags" + vname = "GCC_OPTION (target_flags)" mask = "MASK_" } print "#define TARGET_" nth_arg(1, opt) \ -- 1.8.5.3