@@ -2118,6 +2118,35 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
21182118
21192119 return ;
21202120 }
2121+ else if (identifier == CPROVER_PREFIX " enum_is_in_range" )
2122+ {
2123+ // Check correct number of arguments
2124+ if (expr.arguments ().size () != 1 )
2125+ {
2126+ std::ostringstream error_message;
2127+ error_message << identifier << " takes exactly 1 argument, but "
2128+ << expr.arguments ().size () << " were provided" ;
2129+ throw invalid_source_file_exceptiont{
2130+ error_message.str (), expr.source_location ()};
2131+ }
2132+ const auto &arg1 = expr.arguments ()[0 ];
2133+ if (!can_cast_type<c_enum_tag_typet>(arg1.type ()))
2134+ {
2135+ // Can't enum range check a non-enum
2136+ std::ostringstream error_message;
2137+ error_message << identifier << " expects enum, but ("
2138+ << expr2c (arg1, *this ) << " ) has type `"
2139+ << type2c (arg1.type (), *this ) << ' `' ;
2140+ throw invalid_source_file_exceptiont{
2141+ error_message.str (), expr.source_location ()};
2142+ }
2143+
2144+ enum_is_in_range_exprt in_range{arg1};
2145+ in_range.add_source_location () = expr.source_location ();
2146+ exprt lowered = in_range.lower (*this );
2147+ expr.swap (lowered);
2148+ return ;
2149+ }
21212150 else if (
21222151 auto gcc_polymorphic = typecheck_gcc_polymorphic_builtin (
21232152 identifier, expr.arguments (), f_op.source_location ()))
@@ -3579,34 +3608,6 @@ exprt c_typecheck_baset::do_special_functions(
35793608 overflow.add_source_location () = tmp.source_location ();
35803609 return std::move (overflow);
35813610 }
3582- else if (identifier == CPROVER_PREFIX " enum_is_in_range" )
3583- {
3584- // Check correct number of arguments
3585- if (expr.arguments ().size () != 1 )
3586- {
3587- std::ostringstream error_message;
3588- error_message << identifier << " takes exactly 1 argument, but "
3589- << expr.arguments ().size () << " were provided" ;
3590- throw invalid_source_file_exceptiont{
3591- error_message.str (), expr.source_location ()};
3592- }
3593- auto arg1 = expr.arguments ()[0 ];
3594- typecheck_expr (arg1);
3595- if (!can_cast_type<c_enum_tag_typet>(arg1.type ()))
3596- {
3597- // Can't enum range check a non-enum
3598- std::ostringstream error_message;
3599- error_message << identifier << " expects enum, but ("
3600- << expr2c (arg1, *this ) << " ) has type `"
3601- << type2c (arg1.type (), *this ) << ' `' ;
3602- throw invalid_source_file_exceptiont{
3603- error_message.str (), expr.source_location ()};
3604- }
3605- else
3606- {
3607- return expr;
3608- }
3609- }
36103611 else if (
36113612 identifier == " __builtin_add_overflow" ||
36123613 identifier == " __builtin_sadd_overflow" ||
0 commit comments