gen_settings: dont try to display a Preset descriptor in Flags (#241)
* gen_settings: dont try to display a Preset descriptor in Flags Trying to display a preset doesnt make sense, and before this commit it does not display anything meaningful - the printout just says e.g. "haswell =\n". The offset byte a preset descriptor isnt a valid offset into the flag bytes, it is actually an offset into the PRESETS table. It will cause a panic when the offset is out of bounds for the flag bytes, which happens in the intel isa as of this commit. * intel settings: test that display impl doesnt panic
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
42e1616b82
commit
ed24320eda
@@ -218,11 +218,12 @@ def gen_display(sgrp, fmt):
|
|||||||
'}'):
|
'}'):
|
||||||
fmt.line('writeln!(f, "[{}]")?;'.format(sgrp.name))
|
fmt.line('writeln!(f, "[{}]")?;'.format(sgrp.name))
|
||||||
with fmt.indented('for d in &DESCRIPTORS {', '}'):
|
with fmt.indented('for d in &DESCRIPTORS {', '}'):
|
||||||
fmt.line('write!(f, "{} = ", d.name)?;')
|
with fmt.indented('if !d.detail.is_preset() {', '}'):
|
||||||
fmt.line(
|
fmt.line('write!(f, "{} = ", d.name)?;')
|
||||||
'TEMPLATE.format_toml_value(d.detail,' +
|
fmt.line(
|
||||||
'self.bytes[d.offset as usize], f)?;')
|
'TEMPLATE.format_toml_value(d.detail,' +
|
||||||
fmt.line('writeln!(f, "")?;')
|
'self.bytes[d.offset as usize], f)?;')
|
||||||
|
fmt.line('writeln!(f, "")?;')
|
||||||
fmt.line('Ok(())')
|
fmt.line('Ok(())')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,4 +30,23 @@ mod tests {
|
|||||||
assert_eq!(f2.has_sse41(), true);
|
assert_eq!(f2.has_sse41(), true);
|
||||||
assert_eq!(f2.has_bmi1(), true);
|
assert_eq!(f2.has_bmi1(), true);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn display_presets() {
|
||||||
|
// Spot check that the flags Display impl does not cause a panic
|
||||||
|
let shared = settings::Flags::new(&settings::builder());
|
||||||
|
|
||||||
|
let b1 = builder();
|
||||||
|
let f1 = Flags::new(&shared, &b1);
|
||||||
|
let _ = format!("{}", f1);
|
||||||
|
|
||||||
|
let mut b2 = builder();
|
||||||
|
b2.enable("nehalem").unwrap();
|
||||||
|
let f2 = Flags::new(&shared, &b1);
|
||||||
|
let _ = format!("{}", f2);
|
||||||
|
|
||||||
|
let mut b3 = builder();
|
||||||
|
b3.enable("haswell").unwrap();
|
||||||
|
let f3 = Flags::new(&shared, &b1);
|
||||||
|
let _ = format!("{}", f3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,6 +297,17 @@ pub mod detail {
|
|||||||
/// The `Descriptor::offset` field refers to the `PRESETS` table.
|
/// The `Descriptor::offset` field refers to the `PRESETS` table.
|
||||||
Preset,
|
Preset,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Detail {
|
||||||
|
/// Check if a detail is a Detail::Preset. Useful because the Descriptor
|
||||||
|
/// offset field has a different meaning when the detail is a preset.
|
||||||
|
pub fn is_preset(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
&Detail::Preset => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include code generated by `meta/gen_settings.py`. This file contains a public `Flags` struct
|
// Include code generated by `meta/gen_settings.py`. This file contains a public `Flags` struct
|
||||||
|
|||||||
Reference in New Issue
Block a user