|
13 | 13 |
|
14 | 14 | #include <cassert>
|
15 | 15 |
|
| 16 | +#include <util/arith_tools.h> |
16 | 17 | #include <util/cprover_prefix.h>
|
17 | 18 | #include <util/expr_util.h>
|
18 | 19 | #include <util/fresh_symbol.h>
|
@@ -429,22 +430,32 @@ void goto_convertt::convert_gcc_switch_case_range(
|
429 | 430 | goto_programt tmp;
|
430 | 431 | convert(to_code(code.op2()), tmp, mode);
|
431 | 432 |
|
432 |
| - // goto_programt::targett target=tmp.instructions.begin(); |
| 433 | + goto_programt::targett target = tmp.instructions.begin(); |
433 | 434 | dest.destructive_append(tmp);
|
434 | 435 |
|
435 |
| - #if 0 |
436 |
| - cases_mapt::iterator cases_entry=targets.cases_map.find(target); |
437 |
| - if(cases_entry==targets.cases_map.end()) |
| 436 | + cases_mapt::iterator cases_entry = targets.cases_map.find(target); |
| 437 | + if(cases_entry == targets.cases_map.end()) |
438 | 438 | {
|
439 | 439 | targets.cases.push_back(std::make_pair(target, caset()));
|
440 |
| - cases_entry=targets.cases_map.insert(std::make_pair( |
| 440 | + cases_entry = targets.cases_map.insert(std::make_pair( |
441 | 441 | target, --targets.cases.end())).first;
|
442 | 442 | }
|
443 | 443 |
|
444 |
| - // TODO |
445 |
| - exprt::operandst &case_op_dest=cases_entry->second->second; |
446 |
| - case_op_dest.push_back(code.case_op()); |
447 |
| - #endif |
| 444 | + const auto lb = numeric_cast<mp_integer>(code.op0()); |
| 445 | + const auto ub = numeric_cast<mp_integer>(code.op1()); |
| 446 | + |
| 447 | + if(!lb.has_value() || !ub.has_value()) |
| 448 | + { |
| 449 | + error().source_location = code.find_source_location(); |
| 450 | + error() << "GCC's switch-case-range statement requires integer bounds" |
| 451 | + << eom; |
| 452 | + throw 0; |
| 453 | + } |
| 454 | + |
| 455 | + exprt::operandst &case_op_dest = cases_entry->second->second; |
| 456 | + |
| 457 | + for(mp_integer i = *lb; i <= *ub; ++i) |
| 458 | + case_op_dest.push_back(from_integer(i, code.op0().type())); |
448 | 459 | }
|
449 | 460 |
|
450 | 461 | /// converts 'code' and appends the result to 'dest'
|
|
0 commit comments