Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,11 @@ void c_typecheck_baset::typecheck_side_effect_statement_expression(

code_function_callt &fc=to_code_function_call(last);

const auto &return_type = to_code_type(fc.function().type()).return_type();

side_effect_expr_function_callt sideeffect(
fc.function(), fc.arguments(), return_type, fc.source_location());
fc.function(),
fc.arguments(),
to_code_type(fc.function().type()).return_type(),
fc.source_location());

expr.type()=sideeffect.type();

Expand Down Expand Up @@ -1987,7 +1988,7 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
// This is an undeclared function that's not a builtin.
// Let's just add it.
// We do a bit of return-type guessing, but just a bit.
typet return_type=signed_int_type();
typet guessed_return_type = signed_int_type();

// The following isn't really right and sound, but there
// are too many idiots out there who use malloc and the like
Expand All @@ -1996,14 +1997,16 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
identifier=="realloc" ||
identifier=="reallocf" ||
identifier=="valloc")
return_type=pointer_type(void_type()); // void *
{
guessed_return_type = pointer_type(void_type()); // void *
}

symbolt new_symbol;

new_symbol.name=identifier;
new_symbol.base_name=identifier;
new_symbol.location=expr.source_location();
new_symbol.type = code_typet({}, return_type);
new_symbol.type = code_typet({}, guessed_return_type);
new_symbol.type.set(ID_C_incomplete, true);

// TODO: should also guess some argument types
Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,16 @@ void c_typecheck_baset::typecheck_code_type(code_typet &type)
// "A function declarator shall not specify a return type that
// is a function type or an array type."

const typet &return_type=follow(type.return_type());
const typet &decl_return_type = follow(type.return_type());

if(return_type.id()==ID_array)
if(decl_return_type.id() == ID_array)
{
error().source_location=type.source_location();
error() << "function must not return array" << eom;
throw 0;
}

if(return_type.id()==ID_code)
if(decl_return_type.id() == ID_code)
{
error().source_location=type.source_location();
error() << "function must not return function type" << eom;
Expand Down