Make validation reject 64-bit floating-point literals.

Make expression validation and constant expression validation reject
`Literal` expressions containing `F64` literals unless the `FLOAT64`
capability is enabled.
This commit is contained in:
Jim Blandy 2023-10-18 17:35:41 -07:00 committed by Teodor Tanasoaia
parent 1bb84aef0b
commit 334f745366
2 changed files with 16 additions and 2 deletions

View File

@ -140,6 +140,8 @@ pub enum ConstExpressionError {
Type(#[from] ResolveError),
#[error(transparent)]
Literal(#[from] LiteralError),
#[error(transparent)]
Width(#[from] super::r#type::WidthError),
}
#[derive(Clone, Debug, thiserror::Error)]
@ -149,6 +151,8 @@ pub enum LiteralError {
NaN,
#[error("Float literal is infinite")]
Infinity,
#[error(transparent)]
Width(#[from] super::r#type::WidthError),
}
#[cfg(feature = "validate")]
@ -188,7 +192,7 @@ impl super::Validator {
match gctx.const_expressions[handle] {
E::Literal(literal) => {
check_literal_value(literal)?;
self.validate_literal(literal)?;
}
E::Constant(_) | E::ZeroValue(_) => {}
E::Compose { ref components, ty } => {
@ -343,7 +347,7 @@ impl super::Validator {
ShaderStages::all()
}
E::Literal(literal) => {
check_literal_value(literal)?;
self.validate_literal(literal)?;
ShaderStages::all()
}
E::Constant(_) | E::ZeroValue(_) => ShaderStages::all(),
@ -1563,6 +1567,15 @@ impl super::Validator {
_ => Err(ExpressionError::ExpectedGlobalVariable),
}
}
pub fn validate_literal(&self, literal: crate::Literal) -> Result<(), LiteralError> {
let kind = literal.scalar_kind();
let width = literal.width();
self.check_width(kind, width)?;
check_literal_value(literal)?;
Ok(())
}
}
pub fn check_literal_value(literal: crate::Literal) -> Result<(), LiteralError> {

View File

@ -129,6 +129,7 @@ pub enum TypeError {
}
#[derive(Clone, Debug, thiserror::Error)]
#[cfg_attr(test, derive(PartialEq))]
pub enum WidthError {
#[error("The {0:?} scalar width {1} is not supported")]
Invalid(crate::ScalarKind, crate::Bytes),