Skip to content

Commit d35ad31

Browse files
author
Daniel Kroening
committed
Merge pull request #66 from tautschnig/assert-cleanup
Support klibc's version of __assert_fail, cleanup of assert handling
2 parents 0f407cd + 7ef5cf9 commit d35ad31

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
@@ -1198,60 +1198,31 @@ void goto_convertt::do_function_call_symbol(
11981198
{
11991199
do_printf(lhs, function, arguments, dest);
12001200
}
1201-
else if(identifier=="__assert_fail")
1201+
else if(identifier=="__assert_fail" ||
1202+
identifier=="_assert" ||
1203+
identifier=="__assert_c99" ||
1204+
identifier=="_wassert")
12021205
{
12031206
// __assert_fail is Linux
12041207
// These take four arguments:
12051208
// "expression", "file.c", line, __func__
1209+
// klibc has __assert_fail with 3 arguments
1210+
// "expression", "file.c", line
12061211

1207-
if(arguments.size()!=4)
1208-
{
1209-
err_location(function);
1210-
throw "`"+id2string(identifier)+"' expected to have four arguments";
1211-
}
1212-
1213-
const irep_idt description=
1214-
"assertion "+id2string(get_string_constant(arguments[0]));
1215-
1216-
goto_programt::targett t=dest.add_instruction(ASSERT);
1217-
t->guard=false_exprt();
1218-
t->source_location=function.source_location();
1219-
t->source_location.set("user-provided", true);
1220-
t->source_location.set_property_class(ID_assertion);
1221-
t->source_location.set_comment(description);
1222-
// we ignore any LHS
1223-
}
1224-
else if(identifier=="_assert")
1225-
{
12261212
// MingW has
12271213
// void _assert (const char*, const char*, int);
12281214
// with three arguments:
12291215
// "expression", "file.c", line
12301216

1231-
if(arguments.size()!=3)
1232-
{
1233-
err_location(function);
1234-
throw "`"+id2string(identifier)+"' expected to have three arguments";
1235-
}
1236-
1237-
const irep_idt description=
1238-
"assertion "+id2string(get_string_constant(arguments[0]));
1239-
1240-
goto_programt::targett t=dest.add_instruction(ASSERT);
1241-
t->guard=false_exprt();
1242-
t->source_location=function.source_location();
1243-
t->source_location.set("user-provided", true);
1244-
t->source_location.set_property_class(ID_assertion);
1245-
t->source_location.set_comment(description);
1246-
// we ignore any LHS
1247-
}
1248-
else if(identifier=="__assert_c99")
1249-
{
12501217
// This has been seen in Solaris 11.
12511218
// Signature:
12521219
// void __assert_c99(const char *desc, const char *file, int line, const char *func);
12531220

1254-
if(arguments.size()!=4)
1221+
// _wassert is Windows. The arguments are
1222+
// L"expression", L"file.c", line
1223+
1224+
if(arguments.size()!=4 &&
1225+
arguments.size()!=3)
12551226
{
12561227
err_location(function);
12571228
throw "`"+id2string(identifier)+"' expected to have four arguments";
@@ -1317,28 +1288,6 @@ void goto_convertt::do_function_call_symbol(
13171288

13181289
const irep_idt description=
13191290
"assertion "+id2string(get_string_constant(arguments[3]));
1320-
goto_programt::targett t=dest.add_instruction(ASSERT);
1321-
1322-
t->guard=false_exprt();
1323-
t->source_location=function.source_location();
1324-
t->source_location.set("user-provided", true);
1325-
t->source_location.set_property_class(ID_assertion);
1326-
t->source_location.set_comment(description);
1327-
// we ignore any LHS
1328-
}
1329-
else if(identifier=="_wassert")
1330-
{
1331-
// This is Windows. The arguments are
1332-
// L"expression", L"file.c", line
1333-
1334-
if(arguments.size()!=3)
1335-
{
1336-
err_location(function);
1337-
throw "`"+id2string(identifier)+"' expected to have three arguments";
1338-
}
1339-
1340-
const irep_idt description=
1341-
"assertion "+id2string(get_string_constant(arguments[0]));
13421291

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

0 commit comments

Comments
 (0)