File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -4656,6 +4656,8 @@ class is_compile_time_constantt
4656
4656
4657
4657
void c_typecheck_baset::make_constant (exprt &expr)
4658
4658
{
4659
+ source_locationt location = expr.find_source_location ();
4660
+
4659
4661
// Floating-point expressions may require a rounding mode.
4660
4662
// ISO 9899:1999 F.7.2 says that the default is "round to nearest".
4661
4663
// Some compilers have command-line options to override.
@@ -4664,10 +4666,11 @@ void c_typecheck_baset::make_constant(exprt &expr)
4664
4666
adjust_float_expressions (expr, rounding_mode);
4665
4667
4666
4668
simplify (expr, *this );
4669
+ expr.add_source_location () = location;
4667
4670
4668
4671
if (!is_compile_time_constantt (*this )(expr))
4669
4672
{
4670
- error ().source_location =expr. find_source_location () ;
4673
+ error ().source_location = location ;
4671
4674
error () << " expected constant expression, but got '" << to_string (expr)
4672
4675
<< " '" << eom;
4673
4676
throw 0 ;
@@ -4676,13 +4679,15 @@ void c_typecheck_baset::make_constant(exprt &expr)
4676
4679
4677
4680
void c_typecheck_baset::make_constant_index (exprt &expr)
4678
4681
{
4682
+ source_locationt location = expr.find_source_location ();
4679
4683
make_constant (expr);
4680
4684
make_index_type (expr);
4681
4685
simplify (expr, *this );
4686
+ expr.add_source_location () = location;
4682
4687
4683
4688
if (!is_compile_time_constantt (*this )(expr))
4684
4689
{
4685
- error ().source_location =expr. find_source_location () ;
4690
+ error ().source_location = location ;
4686
4691
error () << " conversion to integer constant failed" << eom;
4687
4692
throw 0 ;
4688
4693
}
Original file line number Diff line number Diff line change @@ -526,6 +526,13 @@ void goto_convertt::convert_switch_case(
526
526
527
527
exprt::operandst &case_op_dest=cases_entry->second ->second ;
528
528
case_op_dest.push_back (code.case_op ());
529
+ // make sure we have a source location in the case operand as otherwise we
530
+ // end up with a GOTO instruction without a source location
531
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
532
+ case_op_dest.back ().source_location ().is_not_nil (),
533
+ " case operand should have a source location" ,
534
+ case_op_dest.back ().pretty (),
535
+ code.pretty ());
529
536
}
530
537
}
531
538
You can’t perform that action at this time.
0 commit comments