Skip to content

Commit 7ef5cf9

Browse files
committed
Support klibc's version of __assert_fail, cleanup of assert handling
1 parent d3f9861 commit 7ef5cf9

File tree

1 file changed

+11
-62
lines changed

1 file changed

+11
-62
lines changed

src/goto-programs/builtin_functions.cpp

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,60 +1283,31 @@ void goto_convertt::do_function_call_symbol(
12831283
{
12841284
do_printf(lhs, function, arguments, dest);
12851285
}
1286-
else if(identifier=="__assert_fail")
1286+
else if(identifier=="__assert_fail" ||
1287+
identifier=="_assert" ||
1288+
identifier=="__assert_c99" ||
1289+
identifier=="_wassert")
12871290
{
12881291
// __assert_fail is Linux
12891292
// These take four arguments:
12901293
// "expression", "file.c", line, __func__
1294+
// klibc has __assert_fail with 3 arguments
1295+
// "expression", "file.c", line
12911296

1292-
if(arguments.size()!=4)
1293-
{
1294-
err_location(function);
1295-
throw "`"+id2string(identifier)+"' expected to have four arguments";
1296-
}
1297-
1298-
const irep_idt description=
1299-
"assertion "+id2string(get_string_constant(arguments[0]));
1300-
1301-
goto_programt::targett t=dest.add_instruction(ASSERT);
1302-
t->guard=false_exprt();
1303-
t->source_location=function.source_location();
1304-
t->source_location.set("user-provided", true);
1305-
t->source_location.set_property_class(ID_assertion);
1306-
t->source_location.set_comment(description);
1307-
// we ignore any LHS
1308-
}
1309-
else if(identifier=="_assert")
1310-
{
13111297
// MingW has
13121298
// void _assert (const char*, const char*, int);
13131299
// with three arguments:
13141300
// "expression", "file.c", line
13151301

1316-
if(arguments.size()!=3)
1317-
{
1318-
err_location(function);
1319-
throw "`"+id2string(identifier)+"' expected to have three arguments";
1320-
}
1321-
1322-
const irep_idt description=
1323-
"assertion "+id2string(get_string_constant(arguments[0]));
1324-
1325-
goto_programt::targett t=dest.add_instruction(ASSERT);
1326-
t->guard=false_exprt();
1327-
t->source_location=function.source_location();
1328-
t->source_location.set("user-provided", true);
1329-
t->source_location.set_property_class(ID_assertion);
1330-
t->source_location.set_comment(description);
1331-
// we ignore any LHS
1332-
}
1333-
else if(identifier=="__assert_c99")
1334-
{
13351302
// This has been seen in Solaris 11.
13361303
// Signature:
13371304
// void __assert_c99(const char *desc, const char *file, int line, const char *func);
13381305

1339-
if(arguments.size()!=4)
1306+
// _wassert is Windows. The arguments are
1307+
// L"expression", L"file.c", line
1308+
1309+
if(arguments.size()!=4 &&
1310+
arguments.size()!=3)
13401311
{
13411312
err_location(function);
13421313
throw "`"+id2string(identifier)+"' expected to have four arguments";
@@ -1402,28 +1373,6 @@ void goto_convertt::do_function_call_symbol(
14021373

14031374
const irep_idt description=
14041375
"assertion "+id2string(get_string_constant(arguments[3]));
1405-
goto_programt::targett t=dest.add_instruction(ASSERT);
1406-
1407-
t->guard=false_exprt();
1408-
t->source_location=function.source_location();
1409-
t->source_location.set("user-provided", true);
1410-
t->source_location.set_property_class(ID_assertion);
1411-
t->source_location.set_comment(description);
1412-
// we ignore any LHS
1413-
}
1414-
else if(identifier=="_wassert")
1415-
{
1416-
// This is Windows. The arguments are
1417-
// L"expression", L"file.c", line
1418-
1419-
if(arguments.size()!=3)
1420-
{
1421-
err_location(function);
1422-
throw "`"+id2string(identifier)+"' expected to have three arguments";
1423-
}
1424-
1425-
const irep_idt description=
1426-
"assertion "+id2string(get_string_constant(arguments[0]));
14271376

14281377
goto_programt::targett t=dest.add_instruction(ASSERT);
14291378
t->guard=false_exprt();

0 commit comments

Comments
 (0)