@@ -2118,6 +2118,77 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
2118
2118
2119
2119
return ;
2120
2120
}
2121
+ else if (identifier == CPROVER_PREFIX " equal" )
2122
+ {
2123
+ if (expr.arguments ().size () != 2 )
2124
+ {
2125
+ error ().source_location = f_op.source_location ();
2126
+ error () << " equal expects two operands" << eom;
2127
+ throw 0 ;
2128
+ }
2129
+
2130
+ equal_exprt equality_expr (
2131
+ expr.arguments ().front (), expr.arguments ().back ());
2132
+ equality_expr.add_source_location () = expr.source_location ();
2133
+
2134
+ if (equality_expr.lhs ().type () != equality_expr.rhs ().type ())
2135
+ {
2136
+ error ().source_location = f_op.source_location ();
2137
+ error () << " equal expects two operands of same type" << eom;
2138
+ throw 0 ;
2139
+ }
2140
+
2141
+ expr.swap (equality_expr);
2142
+ return ;
2143
+ }
2144
+ else if (
2145
+ identifier == CPROVER_PREFIX " overflow_minus" ||
2146
+ identifier == CPROVER_PREFIX " overflow_mult" ||
2147
+ identifier == CPROVER_PREFIX " overflow_plus" ||
2148
+ identifier == CPROVER_PREFIX " overflow_shl" )
2149
+ {
2150
+ exprt overflow{identifier, typet{}, exprt::operandst{expr.arguments ()}};
2151
+ overflow.add_source_location () = f_op.source_location ();
2152
+
2153
+ if (identifier == CPROVER_PREFIX " overflow_minus" )
2154
+ {
2155
+ overflow.id (ID_minus);
2156
+ typecheck_expr_binary_arithmetic (overflow);
2157
+ }
2158
+ else if (identifier == CPROVER_PREFIX " overflow_mult" )
2159
+ {
2160
+ overflow.id (ID_mult);
2161
+ typecheck_expr_binary_arithmetic (overflow);
2162
+ }
2163
+ else if (identifier == CPROVER_PREFIX " overflow_plus" )
2164
+ {
2165
+ overflow.id (ID_plus);
2166
+ typecheck_expr_binary_arithmetic (overflow);
2167
+ }
2168
+ else if (identifier == CPROVER_PREFIX " overflow_shl" )
2169
+ {
2170
+ overflow.id (ID_shl);
2171
+ typecheck_expr_shifts (to_shift_expr (overflow));
2172
+ }
2173
+
2174
+ binary_overflow_exprt of{
2175
+ overflow.operands ()[0 ], overflow.id (), overflow.operands ()[1 ]};
2176
+ of.add_source_location () = overflow.source_location ();
2177
+ expr.swap (of);
2178
+ return ;
2179
+ }
2180
+ else if (identifier == CPROVER_PREFIX " overflow_unary_minus" )
2181
+ {
2182
+ exprt tmp{ID_unary_minus, typet{}, exprt::operandst{expr.arguments ()}};
2183
+ tmp.add_source_location () = f_op.source_location ();
2184
+
2185
+ typecheck_expr_unary_arithmetic (tmp);
2186
+
2187
+ unary_minus_overflow_exprt overflow{tmp.operands ().front ()};
2188
+ overflow.add_source_location () = tmp.source_location ();
2189
+ expr.swap (overflow);
2190
+ return ;
2191
+ }
2121
2192
else if (identifier == CPROVER_PREFIX " enum_is_in_range" )
2122
2193
{
2123
2194
// Check correct number of arguments
@@ -2563,11 +2634,15 @@ exprt c_typecheck_baset::do_special_functions(
2563
2634
2564
2635
typecheck_function_call_arguments (expr);
2565
2636
2637
+ exprt::operandst args_no_cast;
2638
+ args_no_cast.reserve (expr.arguments ().size ());
2566
2639
for (const auto &argument : expr.arguments ())
2567
2640
{
2641
+ args_no_cast.push_back (skip_typecast (argument));
2568
2642
if (
2569
- argument.type ().id () != ID_pointer ||
2570
- to_pointer_type (argument.type ()).base_type ().id () != ID_struct_tag)
2643
+ args_no_cast.back ().type ().id () != ID_pointer ||
2644
+ to_pointer_type (args_no_cast.back ().type ()).base_type ().id () !=
2645
+ ID_struct_tag)
2571
2646
{
2572
2647
error ().source_location = expr.arguments ()[0 ].source_location ();
2573
2648
error () << " is_sentinel_dll_node expects struct-pointer operands"
@@ -2577,7 +2652,7 @@ exprt c_typecheck_baset::do_special_functions(
2577
2652
}
2578
2653
2579
2654
predicate_exprt is_sentinel_dll_expr (" is_sentinel_dll" );
2580
- is_sentinel_dll_expr.operands () = expr. arguments () ;
2655
+ is_sentinel_dll_expr.operands () = args_no_cast ;
2581
2656
is_sentinel_dll_expr.add_source_location () = source_location;
2582
2657
2583
2658
return std::move (is_sentinel_dll_expr);
@@ -3353,30 +3428,6 @@ exprt c_typecheck_baset::do_special_functions(
3353
3428
3354
3429
return std::move (ffs );
3355
3430
}
3356
- else if (identifier==CPROVER_PREFIX " equal" )
3357
- {
3358
- if (expr.arguments ().size ()!=2 )
3359
- {
3360
- error ().source_location = f_op.source_location ();
3361
- error () << " equal expects two operands" << eom;
3362
- throw 0 ;
3363
- }
3364
-
3365
- typecheck_function_call_arguments (expr);
3366
-
3367
- equal_exprt equality_expr (
3368
- expr.arguments ().front (), expr.arguments ().back ());
3369
- equality_expr.add_source_location ()=source_location;
3370
-
3371
- if (equality_expr.lhs ().type () != equality_expr.rhs ().type ())
3372
- {
3373
- error ().source_location = f_op.source_location ();
3374
- error () << " equal expects two operands of same type" << eom;
3375
- throw 0 ;
3376
- }
3377
-
3378
- return std::move (equality_expr);
3379
- }
3380
3431
else if (identifier==" __builtin_expect" )
3381
3432
{
3382
3433
// This is a gcc extension to provide branch prediction.
@@ -3562,52 +3613,6 @@ exprt c_typecheck_baset::do_special_functions(
3562
3613
3563
3614
return tmp;
3564
3615
}
3565
- else if (
3566
- identifier == CPROVER_PREFIX " overflow_minus" ||
3567
- identifier == CPROVER_PREFIX " overflow_mult" ||
3568
- identifier == CPROVER_PREFIX " overflow_plus" ||
3569
- identifier == CPROVER_PREFIX " overflow_shl" )
3570
- {
3571
- exprt overflow{identifier, typet{}, exprt::operandst{expr.arguments ()}};
3572
- overflow.add_source_location () = f_op.source_location ();
3573
-
3574
- if (identifier == CPROVER_PREFIX " overflow_minus" )
3575
- {
3576
- overflow.id (ID_minus);
3577
- typecheck_expr_binary_arithmetic (overflow);
3578
- }
3579
- else if (identifier == CPROVER_PREFIX " overflow_mult" )
3580
- {
3581
- overflow.id (ID_mult);
3582
- typecheck_expr_binary_arithmetic (overflow);
3583
- }
3584
- else if (identifier == CPROVER_PREFIX " overflow_plus" )
3585
- {
3586
- overflow.id (ID_plus);
3587
- typecheck_expr_binary_arithmetic (overflow);
3588
- }
3589
- else if (identifier == CPROVER_PREFIX " overflow_shl" )
3590
- {
3591
- overflow.id (ID_shl);
3592
- typecheck_expr_shifts (to_shift_expr (overflow));
3593
- }
3594
-
3595
- binary_overflow_exprt of{
3596
- overflow.operands ()[0 ], overflow.id (), overflow.operands ()[1 ]};
3597
- of.add_source_location () = overflow.source_location ();
3598
- return std::move (of);
3599
- }
3600
- else if (identifier == CPROVER_PREFIX " overflow_unary_minus" )
3601
- {
3602
- exprt tmp{ID_unary_minus, typet{}, exprt::operandst{expr.arguments ()}};
3603
- tmp.add_source_location () = f_op.source_location ();
3604
-
3605
- typecheck_expr_unary_arithmetic (tmp);
3606
-
3607
- unary_minus_overflow_exprt overflow{tmp.operands ().front ()};
3608
- overflow.add_source_location () = tmp.source_location ();
3609
- return std::move (overflow);
3610
- }
3611
3616
else if (
3612
3617
identifier == " __builtin_add_overflow" ||
3613
3618
identifier == " __builtin_sadd_overflow" ||
0 commit comments