Skip to content
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

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

Closed
mattmccutchen-cci opened this issue Apr 9, 2021 · 1 comment · Fixed by #657
Closed

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

mattmccutchen-cci opened this issue Apr 9, 2021 · 1 comment · Fixed by #657
Labels
benchmark failure A bug causing a failure in our nightly benchmark tests

Comments

@mattmccutchen-cci
Copy link
Member

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.

@mattmccutchen-cci
Copy link
Member Author

I put some other ideas for solutions (more work, but better results) in #531 (comment) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark failure A bug causing a failure in our nightly benchmark tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant