aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-01-13 18:01:19 -0500
committerGitHub <noreply@github.com>2020-01-13 18:01:19 -0500
commitd3e67d99216d3dd6c18259c17652fcad54aebc21 (patch)
treec61934554aeab9798a0bc8ae29ab95c80b54eefe /src/ir.cpp
parentb9f37ffe19e30da1fd79cd01dbb6191ec2733b5c (diff)
parentcae93c860bc2c599618482a4190daf619a0c69e2 (diff)
downloadzig-d3e67d99216d3dd6c18259c17652fcad54aebc21.tar.gz
zig-d3e67d99216d3dd6c18259c17652fcad54aebc21.zip
Merge pull request #4172 from LemonBoy/swish
Two switch-related patches
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index a5561e9bfd..bbf56fd08d 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -26394,6 +26394,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
if (type_is_invalid(end_value->value->type))
return ira->codegen->invalid_instruction;
+ assert(start_value->value->type->id == ZigTypeIdEnum);
BigInt start_index;
bigint_init_bigint(&start_index, &start_value->value->data.x_enum_tag);
@@ -26401,6 +26402,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
BigInt end_index;
bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
+ if (bigint_cmp(&start_index, &end_index) == CmpGT) {
+ ir_add_error(ira, start_value,
+ buf_sprintf("range start value is greater than the end value"));
+ }
+
BigInt field_index;
bigint_init_bigint(&field_index, &start_index);
for (;;) {
@@ -26530,6 +26536,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
+
+ if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
+ ir_add_error(ira, start_value,
+ buf_sprintf("range start value is greater than the end value"));
+ }
+
AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
start_value->source_node);
if (prev_node != nullptr) {