From ae50f31d4f0ae954da1816a5d841201fcab15dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Sun, 12 Jun 2022 18:32:02 +0100 Subject: [PATCH] glsl-in: Don't allow empty last case in switch The GLSL spec forbids switch statements with an empty last case, so we check that now and throw an error if necessary --- src/front/glsl/parser/functions.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/front/glsl/parser/functions.rs b/src/front/glsl/parser/functions.rs index 549b73045b..2f271b8163 100644 --- a/src/front/glsl/parser/functions.rs +++ b/src/front/glsl/parser/functions.rs @@ -276,14 +276,26 @@ impl<'source> ParsingContext<'source> { meta.subsume(end_meta); - // GLSL allows the last case to not have any `break` statement, - // this would mark it as fall trough but naga's IR requires that - // the last case must not be fall trough, so we mark need to mark - // the last case as not fall trough always. - // // NOTE: do not unwrap here since a switch statement isn't required // to have any cases. if let Some(case) = cases.last_mut() { + // GLSL requires that the last case not be empty, so we check + // that here and produce an error otherwise (fall_trough must + // also be checked because `break`s count as statements but + // they aren't added to the body) + if case.body.is_empty() && case.fall_through { + parser.errors.push(Error { + kind: ErrorKind::SemanticError( + "last case/default label must be followed by statements".into(), + ), + meta, + }) + } + + // GLSL allows the last case to not have any `break` statement, + // this would mark it as fall trough but naga's IR requires that + // the last case must not be fall trough, so we mark need to mark + // the last case as not fall trough always. case.fall_through = false; }