Skip to content

Commit 684d19c

Browse files
author
Daniel Kroening
committed
fix return types of various __builtin_is* functions
1 parent a4389fe commit 684d19c

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,10 @@ 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+
if(expr.type()!=isnan_expr.type())
2214+
return typecast_exprt(isnan_expr, expr.type());
2215+
else
2216+
return isnan_expr;
22142217
}
22152218
else if(identifier==CPROVER_PREFIX "isfinitef" ||
22162219
identifier==CPROVER_PREFIX "isfinited" ||
@@ -2226,7 +2229,10 @@ exprt c_typecheck_baset::do_special_functions(
22262229
isfinite_exprt isfinite_expr(expr.arguments().front());
22272230
isfinite_expr.add_source_location()=source_location;
22282231

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;
22302236
}
22312237
else if(identifier==CPROVER_PREFIX "inf" ||
22322238
identifier=="__builtin_inf")
@@ -2298,14 +2304,17 @@ exprt c_typecheck_baset::do_special_functions(
22982304
if(expr.arguments().size()!=1)
22992305
{
23002306
err_location(f_op);
2301-
error() << "isinf expects one operand" << eom;
2307+
error() << identifier << " expects one operand" << eom;
23022308
throw 0;
23032309
}
23042310

23052311
isinf_exprt isinf_expr(expr.arguments().front());
23062312
isinf_expr.add_source_location()=source_location;
23072313

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
23092318
}
23102319
else if(identifier==CPROVER_PREFIX "isnormalf" ||
23112320
identifier==CPROVER_PREFIX "isnormald" ||
@@ -2314,14 +2323,26 @@ exprt c_typecheck_baset::do_special_functions(
23142323
if(expr.arguments().size()!=1)
23152324
{
23162325
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;
23182336
throw 0;
23192337
}
23202338

23212339
isnormal_exprt isnormal_expr(expr.arguments().front());
23222340
isnormal_expr.add_source_location()=source_location;
23232341

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
23252346
}
23262347
else if(identifier==CPROVER_PREFIX "signf" ||
23272348
identifier==CPROVER_PREFIX "signd" ||
@@ -2333,14 +2354,17 @@ exprt c_typecheck_baset::do_special_functions(
23332354
if(expr.arguments().size()!=1)
23342355
{
23352356
err_location(f_op);
2336-
error() << "sign expects one operand" << eom;
2357+
error() << identifier << " expects one operand" << eom;
23372358
throw 0;
23382359
}
23392360

23402361
sign_exprt sign_expr(expr.arguments().front());
23412362
sign_expr.add_source_location()=source_location;
23422363

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
23442368
}
23452369
else if(identifier=="__builtin_popcount" ||
23462370
identifier=="__builtin_popcountl" ||

0 commit comments

Comments
 (0)