Message ID | f34adcc3-9b7f-1b8f-328f-7a267c0e5888@suse.cz |
---|---|
State | New |
Headers | show |
Series | [stage1] optgen: make more sanity checks for enums. | expand |
On Tue, 17 Mar 2020, Martin Liška wrote: > Hi. > > The patch is about better sanity check in option generation script. > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed in stage1? OK.
On 3/17/20 9:46 AM, Martin Liška wrote: > Hi. > > The patch is about better sanity check in option generation script. > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed in stage1? @@ -72,6 +72,19 @@ function opt_args(name, flags) return flags } +# If FLAGS contains a "NAME(...argument...)" flag, return the value +# of the argument. Print error message otherwise. +function opt_args_non_empty(name, flags, description) +{ + args = opt_args(name, flags) + if (args == "") + { + print "Empty option argument '" name "' during parsing of: " flags >> "/dev/stderr" The script reports errors by emitting them as #error directives into standard output (so they cause the build to fail). Should this new routine do the same thing? (/dev/stderr is also not available on all flavors of UNIX but I'm not sure how much that matters here.) Martin + exit 1 + } + return args +} > Thanks, > Martin > > gcc/ChangeLog: > > 2020-03-17 Martin Liska <mliska@suse.cz> > > * opt-functions.awk (opt_args_non_empty): New function. > * opt-read.awk: Use the function for various option arguments. > --- > gcc/opt-functions.awk | 13 +++++++++++++ > gcc/opt-read.awk | 10 +++++----- > 2 files changed, 18 insertions(+), 5 deletions(-) > >
On 3/17/20 11:41 PM, Martin Sebor wrote: > The script reports errors by emitting them as #error directives into > standard output (so they cause the build to fail). Should this new > routine do the same thing? (/dev/stderr is also not available on all > flavors of UNIX but I'm not sure how much that matters here.) Good point Martin. Yes, #error emission works fine here: ./options.h:1:2: error: #error Empty option argument 'Enum' during parsing of: Enum (diagnostic_prefixing_rule) String(once) Value(DIAGNOSTICS_SHOW_PREFIX_ONCE) 1 | #error Empty option argument 'Enum' during parsing of: Enum (diagnostic_prefixing_rule) String(once) Value(DIAGNOSTICS_SHOW_PREFIX_ONCE) | ^~~~~ There's updated version of the patch. Martin
On Wed, 18 Mar 2020, Martin Liška wrote: > On 3/17/20 11:41 PM, Martin Sebor wrote: > > The script reports errors by emitting them as #error directives into > > standard output (so they cause the build to fail). Should this new > > routine do the same thing? (/dev/stderr is also not available on all > > flavors of UNIX but I'm not sure how much that matters here.) > > Good point Martin. Yes, #error emission works fine here: > > ./options.h:1:2: error: #error Empty option argument 'Enum' during parsing of: > Enum (diagnostic_prefixing_rule) String(once) > Value(DIAGNOSTICS_SHOW_PREFIX_ONCE) > 1 | #error Empty option argument 'Enum' during parsing of: Enum > (diagnostic_prefixing_rule) String(once) Value(DIAGNOSTICS_SHOW_PREFIX_ONCE) > | ^~~~~ > > There's updated version of the patch. This version is also OK.
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk index 2f0442dc563..be4b9e66165 100644 --- a/gcc/opt-functions.awk +++ b/gcc/opt-functions.awk @@ -72,6 +72,19 @@ function opt_args(name, flags) return flags } +# If FLAGS contains a "NAME(...argument...)" flag, return the value +# of the argument. Print error message otherwise. +function opt_args_non_empty(name, flags, description) +{ + args = opt_args(name, flags) + if (args == "") + { + print "Empty option argument '" name "' during parsing of: " flags >> "/dev/stderr" + exit 1 + } + return args +} + # Return the Nth comma-separated element of S. Return the empty string # if S does not contain N elements. function nth_arg(n, s) diff --git a/gcc/opt-read.awk b/gcc/opt-read.awk index a2e16f29aff..9bb9dfcf6ca 100644 --- a/gcc/opt-read.awk +++ b/gcc/opt-read.awk @@ -81,8 +81,8 @@ BEGIN { } else if ($1 == "Enum") { props = $2 - name = opt_args("Name", props) - type = opt_args("Type", props) + name = opt_args_non_empty("Name", props) + type = opt_args_non_empty("Type", props) unknown_error = opt_args("UnknownError", props) enum_names[n_enums] = name enum_type[name] = type @@ -93,9 +93,9 @@ BEGIN { } else if ($1 == "EnumValue") { props = $2 - enum_name = opt_args("Enum", props) - string = opt_args("String", props) - value = opt_args("Value", props) + enum_name = opt_args_non_empty("Enum", props) + string = opt_args_non_empty("String", props) + value = opt_args_non_empty("Value", props) val_flags = "0" val_flags = val_flags \ test_flag("Canonical", props, "| CL_ENUM_CANONICAL") \