aboutsummaryrefslogtreecommitdiff
path: root/source/val/validate_cfg.cpp
diff options
context:
space:
mode:
authoralan-baker <alanbaker@google.com>2021-03-02 15:40:56 -0500
committerGitHub <noreply@github.com>2021-03-02 15:40:56 -0500
commit939bc02603933200da5e375cb33f3a381472861c (patch)
treedf1741bade00fb72d7a3e306933d666c2e063a46 /source/val/validate_cfg.cpp
parent0bd920eb9d44e98c33e6462eab787b15bbd731dc (diff)
downloadSPIRV-Tools-939bc02603933200da5e375cb33f3a381472861c.tar.gz
Require an OpSelectionMerge before an OpSwitch (#4154)
Fixes #4153 * OpSwitch is required to be preceeded by OpSelectionMerge * Update newly invalid tests
Diffstat (limited to 'source/val/validate_cfg.cpp')
-rw-r--r--source/val/validate_cfg.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/source/val/validate_cfg.cpp b/source/val/validate_cfg.cpp
index a5f6e6a1..36f632a8 100644
--- a/source/val/validate_cfg.cpp
+++ b/source/val/validate_cfg.cpp
@@ -654,18 +654,15 @@ spv_result_t ValidateStructuredSelections(
<< "Selection must be structured";
}
} else if (terminator->opcode() == SpvOpSwitch) {
- uint32_t count = 0;
- // Mark the targets as seen now, but only error out if this block was
- // missing a merge instruction and there were multiple unseen labels.
+ if (!merge) {
+ return _.diag(SPV_ERROR_INVALID_CFG, terminator)
+ << "OpSwitch must be preceeded by an OpSelectionMerge "
+ "instruction";
+ }
+ // Mark the targets as seen.
for (uint32_t i = 1; i < terminator->operands().size(); i += 2) {
const auto target = terminator->GetOperandAs<uint32_t>(i);
- if (seen.insert(target).second) {
- count++;
- }
- }
- if (!merge && count > 1) {
- return _.diag(SPV_ERROR_INVALID_CFG, terminator)
- << "Selection must be structured";
+ seen.insert(target);
}
}
}