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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user