Skip to content

Commit 71fd395

Browse files
author
Daniel Kroening
committed
fix return types of various __builtin_is* functions
1 parent 89cefef commit 71fd395

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ exprt c_typecheck_baset::do_special_functions(
22102210
isnan_exprt isnan_expr(expr.arguments().front());
22112211
isnan_expr.add_source_location()=source_location;
22122212

2213-
return isnan_expr;
2213+
return typecast_exprt::conditional_cast(isnan_expr, expr.type());
22142214
}
22152215
else if(identifier==CPROVER_PREFIX "isfinitef" ||
22162216
identifier==CPROVER_PREFIX "isfinited" ||
@@ -2226,7 +2226,10 @@ exprt c_typecheck_baset::do_special_functions(
22262226
isfinite_exprt isfinite_expr(expr.arguments().front());
22272227
isfinite_expr.add_source_location()=source_location;
22282228

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;
22302233
}
22312234
else if(identifier==CPROVER_PREFIX "inf" ||
22322235
identifier=="__builtin_inf")
@@ -2298,14 +2301,14 @@ exprt c_typecheck_baset::do_special_functions(
22982301
if(expr.arguments().size()!=1)
22992302
{
23002303
err_location(f_op);
2301-
error() << "isinf expects one operand" << eom;
2304+
error() << identifier << " expects one operand" << eom;
23022305
throw 0;
23032306
}
23042307

23052308
isinf_exprt isinf_expr(expr.arguments().front());
23062309
isinf_expr.add_source_location()=source_location;
23072310

2308-
return isinf_expr;
2311+
return typecast_exprt::conditional_cast(isinf_expr, expr.type());
23092312
}
23102313
else if(identifier==CPROVER_PREFIX "isnormalf" ||
23112314
identifier==CPROVER_PREFIX "isnormald" ||
@@ -2314,14 +2317,23 @@ exprt c_typecheck_baset::do_special_functions(
23142317
if(expr.arguments().size()!=1)
23152318
{
23162319
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;
23182330
throw 0;
23192331
}
23202332

23212333
isnormal_exprt isnormal_expr(expr.arguments().front());
23222334
isnormal_expr.add_source_location()=source_location;
23232335

2324-
return isnormal_expr;
2336+
return typecast_exprt::conditional_cast(isnormal_expr, expr.type());
23252337
}
23262338
else if(identifier==CPROVER_PREFIX "signf" ||
23272339
identifier==CPROVER_PREFIX "signd" ||
@@ -2333,14 +2345,17 @@ exprt c_typecheck_baset::do_special_functions(
23332345
if(expr.arguments().size()!=1)
23342346
{
23352347
err_location(f_op);
2336-
error() << "sign expects one operand" << eom;
2348+
error() << identifier << " expects one operand" << eom;
23372349
throw 0;
23382350
}
23392351

23402352
sign_exprt sign_expr(expr.arguments().front());
23412353
sign_expr.add_source_location()=source_location;
23422354

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
23442359
}
23452360
else if(identifier=="__builtin_popcount" ||
23462361
identifier=="__builtin_popcountl" ||

0 commit comments

Comments
 (0)