Skip to content

3c -alltypes deletes bodies of unnamed struct types #542

Closed
@mattmccutchen-cci

Description

@mattmccutchen-cci

When 3c -alltypes is run on the following input:

struct {} *x;

struct {} y[1];

it produces the following warnings:

/home/matt/test/unnamed-struct.c:1:12: warning: 
 Rewriting failedfor 'x' because an inline or anonymous struct instance was detected.
 Consider manually rewriting by inserting the struct definition inside the _Ptr annotation.
 EX. struct {int *a; int *b;} x; _Ptr<struct {int *a; _Ptr<int> b;}>;
struct {} *x;
           ^
/home/matt/test/unnamed-struct.c:3:11: warning: 
 Rewriting failedfor 'y' because an inline or anonymous struct instance was detected.
 Consider manually rewriting by inserting the struct definition inside the _Ptr annotation.
 EX. struct {int *a; int *b;} x; _Ptr<struct {int *a; _Ptr<int> b;}>;
struct {} y[1];
          ^

and the following output:

_Ptr<struct> x = ((void *)0);

struct y _Checked[1];

which produces the following compile errors (included here for ease of finding this issue in a search):

unnamed-struct.checked.c:1:6: error: declaration of anonymous struct must be a definition
_Ptr<struct> x = ((void *)0);
     ^
unnamed-struct.checked.c:1:29: error: expected a type
_Ptr<struct> x = ((void *)0);
                            ^
unnamed-struct.checked.c:1:1: warning: declaration does not declare anything [-Wmissing-declarations]
_Ptr<struct> x = ((void *)0);
^
unnamed-struct.checked.c:3:10: error: expected identifier or '('
struct y _Checked[1];
         ^

The 3C warning (added in #366) suggests that we knew that 3C doesn't handle this case correctly, but we don't seem to have an open issue for that, so I'm filing this one. Apparently this "rewriting" of inline structs is another 3C feature controlled by -alltypes that I was unaware of; indeed, it ~"tries to generate output that is closer to what you ultimately want but may not pass the type checker right away without manual corrections" (here's our documentation). But 3C should be able to handle this in some more graceful way than introducing syntax errors that may confuse users new to Checked C. Maybe 3C could insert a dummy struct name that would cause an "undefined struct" error instead of a syntax error; then users who overlooked the 3C warning could search the web for the dummy struct name and find this issue.

This is causing a handful of errors in our benchmarks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    benchmark failureA bug causing a failure in our nightly benchmark tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions