@@ -2210,7 +2210,7 @@ exprt c_typecheck_baset::do_special_functions(
2210
2210
isnan_exprt isnan_expr (expr.arguments ().front ());
2211
2211
isnan_expr.add_source_location ()=source_location;
2212
2212
2213
- return isnan_expr;
2213
+ return typecast_exprt::conditional_cast ( isnan_expr, expr. type ()) ;
2214
2214
}
2215
2215
else if (identifier==CPROVER_PREFIX " isfinitef" ||
2216
2216
identifier==CPROVER_PREFIX " isfinited" ||
@@ -2226,7 +2226,10 @@ exprt c_typecheck_baset::do_special_functions(
2226
2226
isfinite_exprt isfinite_expr (expr.arguments ().front ());
2227
2227
isfinite_expr.add_source_location ()=source_location;
2228
2228
2229
- return isfinite_expr;
2229
+ if (expr.type ()!=isfinite_expr.type ())
2230
+ return typecast_exprt (isfinite_expr, expr.type ());
2231
+ else
2232
+ return isfinite_expr;
2230
2233
}
2231
2234
else if (identifier==CPROVER_PREFIX " inf" ||
2232
2235
identifier==" __builtin_inf" )
@@ -2298,14 +2301,14 @@ exprt c_typecheck_baset::do_special_functions(
2298
2301
if (expr.arguments ().size ()!=1 )
2299
2302
{
2300
2303
err_location (f_op);
2301
- error () << " isinf expects one operand" << eom;
2304
+ error () << identifier << " expects one operand" << eom;
2302
2305
throw 0 ;
2303
2306
}
2304
2307
2305
2308
isinf_exprt isinf_expr (expr.arguments ().front ());
2306
2309
isinf_expr.add_source_location ()=source_location;
2307
2310
2308
- return isinf_expr;
2311
+ return typecast_exprt::conditional_cast ( isinf_expr, expr. type ()) ;
2309
2312
}
2310
2313
else if (identifier==CPROVER_PREFIX " isnormalf" ||
2311
2314
identifier==CPROVER_PREFIX " isnormald" ||
@@ -2314,14 +2317,23 @@ exprt c_typecheck_baset::do_special_functions(
2314
2317
if (expr.arguments ().size ()!=1 )
2315
2318
{
2316
2319
err_location (f_op);
2317
- error () << " isnormal expects one operand" << eom;
2320
+ error () << identifier << " expects one operand" << eom;
2321
+ throw 0 ;
2322
+ }
2323
+
2324
+ const exprt &fp_value = expr.arguments ()[0 ];
2325
+
2326
+ if (fp_value.type ().id () != ID_floatbv)
2327
+ {
2328
+ err_location (fp_value);
2329
+ error () << " non-floating-point argument for " << identifier << eom;
2318
2330
throw 0 ;
2319
2331
}
2320
2332
2321
2333
isnormal_exprt isnormal_expr (expr.arguments ().front ());
2322
2334
isnormal_expr.add_source_location ()=source_location;
2323
2335
2324
- return isnormal_expr;
2336
+ return typecast_exprt::conditional_cast ( isnormal_expr, expr. type ()) ;
2325
2337
}
2326
2338
else if (identifier==CPROVER_PREFIX " signf" ||
2327
2339
identifier==CPROVER_PREFIX " signd" ||
@@ -2333,14 +2345,17 @@ exprt c_typecheck_baset::do_special_functions(
2333
2345
if (expr.arguments ().size ()!=1 )
2334
2346
{
2335
2347
err_location (f_op);
2336
- error () << " sign expects one operand" << eom;
2348
+ error () << identifier << " expects one operand" << eom;
2337
2349
throw 0 ;
2338
2350
}
2339
2351
2340
2352
sign_exprt sign_expr (expr.arguments ().front ());
2341
2353
sign_expr.add_source_location ()=source_location;
2342
2354
2343
- return sign_expr;
2355
+ if (expr.type ()!=sign_expr.type ())
2356
+ return typecast_exprt (sign_expr, expr.type ()); // int
2357
+ else
2358
+ return sign_expr; // bool
2344
2359
}
2345
2360
else if (identifier==" __builtin_popcount" ||
2346
2361
identifier==" __builtin_popcountl" ||
0 commit comments