This patch, for 4.7 and relative to a tree with <http://gcc.gnu.org/ml/gcc-patches/2011-02/msg01709.html> applied, stops the M32C handle_option hook from using global state. All the hook did was process an integer argument and set a variable to indicate that the option had been used explicitly; this can all be done with .opt features, so the hook is removed and replaced with use of UInteger in m32c.opt (nothing made any use of the string variable previously set by the option through use of Var there without UInteger). (This means that there is now error checking that the argument actually has the syntax of a nonnegative integer rather than blindly passing any argument to atoi. So there's one fewer use of atoi that will need removing to fix PR 44574.)
Tested building cc1 and xgcc for cross to m32c-elf. Will commit to trunk for 4.7 in the absence of target maintainer objections. 2011-03-03 Joseph Myers <jos...@codesourcery.com> * config/m32c/m32c.c: Don't include opts.h. (target_memregs, target_memregs_set, TARGET_HANDLE_OPTION, m32c_handle_option): Remove. (m32c_option_override): Check global_options_set.x_target_memregs instead of target_memregs_set. * config/m32c/m32c.h (target_memregs): Remove. * config/m32c/m32c.opt (memregs=): Use UInteger with integer variable. diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/m32c/m32c.c gcc-mainline/gcc/config/m32c/m32c.c --- gcc-mainline-1/gcc/config/m32c/m32c.c 2011-02-23 16:00:03.000000000 -0800 +++ gcc-mainline/gcc/config/m32c/m32c.c 2011-03-03 17:14:56.000000000 -0800 @@ -48,7 +48,6 @@ #include "langhooks.h" #include "gimple.h" #include "df.h" -#include "opts.h" /* Prototypes */ @@ -408,31 +407,8 @@ class_can_hold_mode (reg_class_t rclass, Memregs are provided by m32c-lib1.S. */ -int target_memregs = 16; -static bool target_memregs_set = FALSE; int ok_to_change_target_memregs = TRUE; -#undef TARGET_HANDLE_OPTION -#define TARGET_HANDLE_OPTION m32c_handle_option -static bool -m32c_handle_option (struct gcc_options *opts, struct gcc_options *opts_set, - const struct cl_decoded_option *decoded, - location_t loc ATTRIBUTE_UNUSED) -{ - size_t code = decoded->opt_index; - const char *arg = decoded->arg; - - gcc_assert (opts == &global_options); - gcc_assert (opts_set == &global_options_set); - - if (code == OPT_memregs_) - { - target_memregs_set = TRUE; - target_memregs = atoi (arg); - } - return TRUE; -} - /* Implements TARGET_OPTION_OVERRIDE. */ #undef TARGET_OPTION_OVERRIDE @@ -442,7 +418,7 @@ static void m32c_option_override (void) { /* We limit memregs to 0..16, and provide a default. */ - if (target_memregs_set) + if (global_options_set.x_target_memregs) { if (target_memregs < 0 || target_memregs > 16) error ("invalid target memregs value '%d'", target_memregs); diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/m32c/m32c.h gcc-mainline/gcc/config/m32c/m32c.h --- gcc-mainline-1/gcc/config/m32c/m32c.h 2011-02-16 15:01:11.000000000 -0800 +++ gcc-mainline/gcc/config/m32c/m32c.h 2011-03-03 17:15:06.000000000 -0800 @@ -86,7 +86,6 @@ beginning of the file. This variable starts off TRUE and later becomes FALSE. */ extern int ok_to_change_target_memregs; -extern int target_memregs; /* TARGET_CPU is a multi-way option set in m32c.opt. While we could use enums or defines for this, this and m32c.opt are the only diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/m32c/m32c.opt gcc-mainline/gcc/config/m32c/m32c.opt --- gcc-mainline-1/gcc/config/m32c/m32c.opt 2009-03-28 00:38:02.000000000 -0700 +++ gcc-mainline/gcc/config/m32c/m32c.opt 2011-03-03 17:14:10.000000000 -0800 @@ -1,5 +1,5 @@ ; Target Options for R8C/M16C/M32C -; Copyright (C) 2005 2007 +; Copyright (C) 2005, 2007, 2011 ; Free Software Foundation, Inc. ; Contributed by Red Hat. ; @@ -40,5 +40,5 @@ Target RejectNegative Var(target_cpu,'3' -mcpu=m32c Compile code for M32C variants memregs= -Target RejectNegative Joined Var(target_memregs_string) +Target RejectNegative Joined UInteger Var(target_memregs) Init(16) -memregs= Number of memreg bytes (default: 16, range: 0..16) -- Joseph S. Myers jos...@codesourcery.com