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