From 2b4b9bd65b9fb9d5cfc5f50ebb9fafd84a1b5758 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sat, 18 Jul 2015 11:13:14 -0600 Subject: [PATCH] Front-end: Add error-recovery code for a switch statement that ends with a case/default that has no statements. --- Test/baseResults/switch.frag.out | 8 ++++++++ glslang/Include/intermediate.h | 2 +- glslang/MachineIndependent/ParseHelper.cpp | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Test/baseResults/switch.frag.out b/Test/baseResults/switch.frag.out index a500270f..b3d3ce0c 100644 --- a/Test/baseResults/switch.frag.out +++ b/Test/baseResults/switch.frag.out @@ -37,6 +37,8 @@ ERROR: node is still EOpNull! 0:23 case: with expression 0:23 Constant: 0:23 2 (const int) +0:21 Sequence +0:21 Branch: Break 0:26 switch 0:26 condition 0:26 'c' (uniform mediump int) @@ -300,6 +302,8 @@ ERROR: node is still EOpNull! 0:128 body 0:128 Sequence 0:129 default: +0:128 Sequence +0:128 Branch: Break 0:133 switch 0:133 condition 0:133 'c' (uniform mediump int) @@ -369,6 +373,8 @@ ERROR: node is still EOpNull! 0:23 case: with expression 0:23 Constant: 0:23 2 (const int) +0:21 Sequence +0:21 Branch: Break 0:26 switch 0:26 condition 0:26 'c' (uniform mediump int) @@ -632,6 +638,8 @@ ERROR: node is still EOpNull! 0:128 body 0:128 Sequence 0:129 default: +0:128 Sequence +0:128 Branch: Break 0:133 switch 0:133 condition 0:133 'c' (uniform mediump int) diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h index 2232c01e..2b14d79f 100644 --- a/glslang/Include/intermediate.h +++ b/glslang/Include/intermediate.h @@ -641,7 +641,7 @@ public: virtual TIntermAggregate* getAsAggregate() { return this; } virtual const TIntermAggregate* getAsAggregate() const { return this; } virtual void setOperator(TOperator o) { op = o; } - virtual TIntermSequence& getSequence() { return sequence; } + virtual TIntermSequence& getSequence() { return sequence; } virtual const TIntermSequence& getSequence() const { return sequence; } virtual void setName(const TString& n) { name = n; } virtual const TString& getName() const { return name; } diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 9db85c1d..86356778 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5287,6 +5287,11 @@ TIntermNode* TParseContext::addSwitch(TSourceLoc loc, TIntermTyped* expression, error(loc, "last case/default label not followed by statements", "switch", ""); else warn(loc, "last case/default label not followed by statements", "switch", ""); + + // emulate a break for error recovery + lastStatements = intermediate.makeAggregate(intermediate.addBranch(EOpBreak, loc)); + lastStatements->setOperator(EOpSequence); + switchSequence->push_back(lastStatements); } TIntermAggregate* body = new TIntermAggregate(EOpSequence);