Skip to content

C/C++ front-end: do not accept void-typed objects or members #5676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2020
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
21 changes: 21 additions & 0 deletions regression/ansi-c/invalid_use_of_void1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct a
{
#ifdef void_member
void b;
#else
int b;
#endif
};
struct a *ae;
void d()
{
ae->b;
}
#ifdef void_global
void x;
#endif
int main()
{
void v;
d();
}
9 changes: 9 additions & 0 deletions regression/ansi-c/invalid_use_of_void1/test-global.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE test-c++-front-end
main.c
-Dvoid_global
^EXIT=(64|1)$
^SIGNAL=0$
void-typed symbol not permitted
^CONVERSION ERROR$
--
Invariant check failed
9 changes: 9 additions & 0 deletions regression/ansi-c/invalid_use_of_void1/test-non-member.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE test-c++-front-end
main.c

^EXIT=(64|1)$
^SIGNAL=0$
void-typed symbol not permitted
^CONVERSION ERROR$
--
Invariant check failed
9 changes: 9 additions & 0 deletions regression/ansi-c/invalid_use_of_void1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE test-c++-front-end
main.c
-Dvoid_member
^EXIT=(64|1)$
^SIGNAL=0$
void-typed member not permitted
^CONVERSION ERROR$
--
Invariant check failed
7 changes: 7 additions & 0 deletions src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
symbol.pretty_name=new_name;
}

if(!symbol.is_type && symbol.type.id() == ID_empty)
{
error().source_location = symbol.location;
error() << "void-typed symbol not permitted" << eom;
throw 0;
}

// see if we have it already
symbol_tablet::symbolst::const_iterator old_it=
symbol_table.symbols.find(symbol.name);
Expand Down
7 changes: 7 additions & 0 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,13 @@ void c_typecheck_baset::typecheck_compound_body(
throw 0;
}

if(new_component.type().id() == ID_empty)
{
error().source_location = source_location;
error() << "void-typed member not permitted" << eom;
throw 0;
}

components.push_back(new_component);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/cpp_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ void cpp_typecheckt::typecheck_decl(codet &code)
if(is_typedef)
continue;

if(!symbol.is_type && symbol.type.id() == ID_empty)
{
error().source_location = symbol.location;
error() << "void-typed symbol not permitted" << eom;
throw 0;
}

code_declt decl_statement(cpp_symbol_expr(symbol));
decl_statement.add_source_location()=symbol.location;

Expand Down
7 changes: 7 additions & 0 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ void cpp_typecheckt::typecheck_compound_declarator(

typecheck_type(final_type);

if(final_type.id() == ID_empty)
{
error().source_location = declaration.type().source_location();
error() << "void-typed member not permitted" << eom;
throw 0;
}

cpp_namet cpp_name;
cpp_name.swap(declarator.name());

Expand Down
7 changes: 7 additions & 0 deletions src/cpp/cpp_typecheck_declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ void cpp_typecheckt::convert_non_template_declaration(
declaration_type, declaration.storage_spec(),
declaration.member_spec(), declarator);

if(!symbol.is_type && symbol.type.id() == ID_empty)
{
error().source_location = symbol.location;
error() << "void-typed symbol not permitted" << eom;
throw 0;
}

// any template instance to remember?
if(declaration.find(ID_C_template).is_not_nil())
{
Expand Down