Skip to content

Commit 87d467e

Browse files
author
Daniel Kroening
committed
fix return types of various __builtin_is* functions
1 parent 61af061 commit 87d467e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/ansi-c/c_typecheck_expr.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ exprt c_typecheck_baset::do_special_functions(
22552255
isnan_exprt isnan_expr(expr.arguments().front());
22562256
isnan_expr.add_source_location()=source_location;
22572257

2258-
return isnan_expr;
2258+
return typecast_exprt::conditional_cast(isnan_expr, expr.type());
22592259
}
22602260
else if(identifier==CPROVER_PREFIX "isfinitef" ||
22612261
identifier==CPROVER_PREFIX "isfinited" ||
@@ -2271,7 +2271,7 @@ exprt c_typecheck_baset::do_special_functions(
22712271
isfinite_exprt isfinite_expr(expr.arguments().front());
22722272
isfinite_expr.add_source_location()=source_location;
22732273

2274-
return isfinite_expr;
2274+
return typecast_exprt::conditional_cast(isfinite_expr, expr.type());
22752275
}
22762276
else if(identifier==CPROVER_PREFIX "inf" ||
22772277
identifier=="__builtin_inf")
@@ -2343,14 +2343,14 @@ exprt c_typecheck_baset::do_special_functions(
23432343
if(expr.arguments().size()!=1)
23442344
{
23452345
err_location(f_op);
2346-
error() << "isinf expects one operand" << eom;
2346+
error() << identifier << " expects one operand" << eom;
23472347
throw 0;
23482348
}
23492349

23502350
isinf_exprt isinf_expr(expr.arguments().front());
23512351
isinf_expr.add_source_location()=source_location;
23522352

2353-
return isinf_expr;
2353+
return typecast_exprt::conditional_cast(isinf_expr, expr.type());
23542354
}
23552355
else if(identifier==CPROVER_PREFIX "isnormalf" ||
23562356
identifier==CPROVER_PREFIX "isnormald" ||
@@ -2359,14 +2359,23 @@ exprt c_typecheck_baset::do_special_functions(
23592359
if(expr.arguments().size()!=1)
23602360
{
23612361
err_location(f_op);
2362-
error() << "isnormal expects one operand" << eom;
2362+
error() << identifier << " expects one operand" << eom;
2363+
throw 0;
2364+
}
2365+
2366+
const exprt &fp_value = expr.arguments()[0];
2367+
2368+
if(fp_value.type().id() != ID_floatbv)
2369+
{
2370+
err_location(fp_value);
2371+
error() << "non-floating-point argument for " << identifier << eom;
23632372
throw 0;
23642373
}
23652374

23662375
isnormal_exprt isnormal_expr(expr.arguments().front());
23672376
isnormal_expr.add_source_location()=source_location;
23682377

2369-
return isnormal_expr;
2378+
return typecast_exprt::conditional_cast(isnormal_expr, expr.type());
23702379
}
23712380
else if(identifier==CPROVER_PREFIX "signf" ||
23722381
identifier==CPROVER_PREFIX "signd" ||
@@ -2378,14 +2387,14 @@ exprt c_typecheck_baset::do_special_functions(
23782387
if(expr.arguments().size()!=1)
23792388
{
23802389
err_location(f_op);
2381-
error() << "sign expects one operand" << eom;
2390+
error() << identifier << " expects one operand" << eom;
23822391
throw 0;
23832392
}
23842393

23852394
sign_exprt sign_expr(expr.arguments().front());
23862395
sign_expr.add_source_location()=source_location;
23872396

2388-
return sign_expr;
2397+
return typecast_exprt::conditional_cast(sign_expr, expr.type());
23892398
}
23902399
else if(identifier=="__builtin_popcount" ||
23912400
identifier=="__builtin_popcountl" ||

0 commit comments

Comments
 (0)