cranelift: Correctly recover from parsing unknown values (#4447)

When parsing isa specific values we were accidentally discarding the
value of the flag, and treating it always as a boolean flag.

This would cause a `clif-util` invocation such as
`cargo run -- compile -D --set has_sse41=false --target x86_64 test.clif`

to be interpreted as `--set has_sse41` and enable that feature instead
of disabling it.
This commit is contained in:
Afonso Bordado
2022-07-14 21:07:58 +01:00
committed by GitHub
parent f7767eb352
commit fc72b7ccd3
2 changed files with 23 additions and 1 deletions

View File

@@ -46,6 +46,16 @@ pub enum ParseOptionError {
/// Name of the unknown flag.
name: String,
},
/// An unknown value was used, with the given name at the given location.
UnknownValue {
/// Location where the flag was given.
loc: Location,
/// Name of the unknown value.
name: String,
/// Value of the unknown value.
value: String,
},
}
impl From<ParseOptionError> for ParseError {
@@ -57,6 +67,11 @@ impl From<ParseOptionError> for ParseError {
message: format!("unknown setting '{}'", name),
is_warning: false,
},
ParseOptionError::UnknownValue { loc, name, value } => Self {
location: loc,
message: format!("unknown setting '{}={}'", name, value),
is_warning: false,
},
}
}
}
@@ -92,7 +107,11 @@ where
TestOption::Value(name, value) => match config.set(name, value) {
Ok(_) => {}
Err(SetError::BadName(name)) => {
return Err(ParseOptionError::UnknownFlag { loc, name })
return Err(ParseOptionError::UnknownValue {
loc,
name,
value: value.to_string(),
})
}
Err(SetError::BadType) => {
return option_err!(loc, "invalid setting type: '{}'", opt)

View File

@@ -64,6 +64,9 @@ pub fn parse_sets_and_triple(
Err(ParseOptionError::UnknownFlag { name, .. }) => {
unknown_settings.push(name);
}
Err(ParseOptionError::UnknownValue { name, value, .. }) => {
unknown_settings.push(format!("{}={}", name, value));
}
Err(ParseOptionError::Generic(err)) => return Err(err.into()),
Ok(()) => {}
}