Skip to content

better location for compound members #2997

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
Sep 29, 2018
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
10 changes: 10 additions & 0 deletions regression/ansi-c/Incomplete_Type1/incomplete_component.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
typedef struct incomplete_struct t;

struct
{
t x;
};

int main()
{
}
9 changes: 9 additions & 0 deletions regression/ansi-c/Incomplete_Type1/incomplete_component.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
incomplete_component.c

^EXIT=(1|64)$
^SIGNAL=0$
^CONVERSION ERROR$
^incomplete_component\.c:5:1: error: incomplete type not permitted here$
--
^warning: ignoring
11 changes: 8 additions & 3 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,13 @@ void c_typecheck_baset::typecheck_compound_body(
struct_union_typet::componentt new_component(
declarator.get_base_name(), declaration.full_type(declarator));

new_component.add_source_location()=
declarator.source_location();
// There may be a declarator, which we use as location for
// the component. Otherwise, use location of the declaration.
const source_locationt source_location =
declarator.get_name().empty() ? declaration.source_location()
: declarator.source_location();

new_component.add_source_location() = source_location;
new_component.set_pretty_name(declarator.get_base_name());

typecheck_type(new_component.type());
Expand All @@ -882,7 +887,7 @@ void c_typecheck_baset::typecheck_compound_body(
(new_component.type().id()!=ID_array ||
!to_array_type(new_component.type()).is_incomplete()))
{
error().source_location=new_component.type().source_location();
error().source_location = source_location;
error() << "incomplete type not permitted here" << eom;
throw 0;
}
Expand Down
5 changes: 4 additions & 1 deletion src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,8 @@ member_declaration:
| member_default_declaring_list ';'
| ';' /* empty declaration */
{
init($$, ID_declaration);
$$=$1; // the ';' becomes the location of the declaration
stack($$).id(ID_declaration);
}
| static_assert_declaration ';'
;
Expand All @@ -1651,6 +1652,7 @@ member_default_declaring_list:

init($$, ID_declaration);
to_ansi_c_declaration(stack($$)).set_is_member(true);
stack($$).add_source_location()=stack($2).source_location();
stack($$).type().swap(stack($2));
PARSER.add_declarator(stack($$), stack($3));
}
Expand Down Expand Up @@ -1686,6 +1688,7 @@ member_declaring_list:

init($$, ID_declaration);
to_ansi_c_declaration(stack($$)).set_is_member(true);
stack($$).add_source_location()=stack($2).source_location();
stack($$).type().swap(stack($2));
PARSER.add_declarator(stack($$), stack($3));
}
Expand Down