Skip to content

Commit afbb31e

Browse files
andyleisersonteoxoy
authored andcommitted
fix(naga): Disallow const shifts of scalar by vector or vice-versa
1 parent dbab82f commit afbb31e

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

cts_runner/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ webgpu:shader,validation,expression,access,array:early_eval_errors:case="overrid
326326
webgpu:shader,validation,expression,access,structure:*
327327
webgpu:shader,validation,expression,binary,add_sub_mul:scalar_vector_out_of_range:lhs="i32";*
328328
webgpu:shader,validation,expression,binary,add_sub_mul:scalar_vector_out_of_range:lhs="u32";*
329+
webgpu:shader,validation,expression,binary,bitwise_shift:scalar_vector:*
329330
webgpu:shader,validation,expression,binary,parse:*
330331
webgpu:shader,validation,expression,binary,short_circuiting_and_or:array_override:op="%26%26";a_val=1;b_val=1
331332
webgpu:shader,validation,expression,binary,short_circuiting_and_or:invalid_types:*

naga/src/proc/constant_evaluator.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,26 +2753,36 @@ impl<'a> ConstantEvaluator<'a> {
27532753
ty,
27542754
},
27552755
&Expression::Literal(_),
2756-
) => {
2757-
let mut components = src_components.clone();
2758-
for component in &mut components {
2759-
*component = self.binary_op(op, *component, right, span)?;
2756+
) => match op {
2757+
BinaryOperator::ShiftLeft | BinaryOperator::ShiftRight => {
2758+
return Err(ConstantEvaluatorError::InvalidBinaryOpArgs);
27602759
}
2761-
Expression::Compose { ty, components }
2762-
}
2760+
_ => {
2761+
let mut components = src_components.clone();
2762+
for component in &mut components {
2763+
*component = self.binary_op(op, *component, right, span)?;
2764+
}
2765+
Expression::Compose { ty, components }
2766+
}
2767+
},
27632768
(
27642769
&Expression::Literal(_),
27652770
&Expression::Compose {
27662771
components: ref src_components,
27672772
ty,
27682773
},
2769-
) => {
2770-
let mut components = src_components.clone();
2771-
for component in &mut components {
2772-
*component = self.binary_op(op, left, *component, span)?;
2774+
) => match op {
2775+
BinaryOperator::ShiftLeft | BinaryOperator::ShiftRight => {
2776+
return Err(ConstantEvaluatorError::InvalidBinaryOpArgs);
27732777
}
2774-
Expression::Compose { ty, components }
2775-
}
2778+
_ => {
2779+
let mut components = src_components.clone();
2780+
for component in &mut components {
2781+
*component = self.binary_op(op, left, *component, span)?;
2782+
}
2783+
Expression::Compose { ty, components }
2784+
}
2785+
},
27762786
(
27772787
&Expression::Compose {
27782788
components: ref left_components,

0 commit comments

Comments
 (0)