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

translate-c fails silently when source code initializes a struct to zero #3752

Closed
kavika13 opened this issue Nov 24, 2019 · 2 comments · Fixed by #4078
Closed

translate-c fails silently when source code initializes a struct to zero #3752

kavika13 opened this issue Nov 24, 2019 · 2 comments · Fixed by #4078
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@kavika13
Copy link
Contributor

kavika13 commented Nov 24, 2019

If you have a C function that initializes a struct instance to { 0 } and run translate-c on it, then zig skips codegen for that function, and doesn't output any error messages.

This was confusing to me because the function didn't output at all. I only figured it out when I did a "binary chop" on the input file to figure out which particular line was keeping the function from being output.

Ideally this would just work, but if it fails to work it would be nice if a good error message was output.

Repro steps:

  1. Create a C example file and save it as main.c:
typedef struct {
    int abc;
} SomeStruct;

int main() {
    SomeStruct blah;
    return 0;
}
  1. zig translate-c main.c > main.zig
  2. Change the line SomeStruct blah; to SomeStruct blah = { 0 }; inside main.c and save it
  3. zig translate-c main.c > main.zig

Expected:
The implementation of fn main() exists in main.zig after both step 2 and step 4
or
An error message is displayed after step 4 that says translate-c cannot cope

Actual:
The implementation of fn main() exists in main.zig after step 2, but disappears after step 4. No error message is displayed.

@daurnimator daurnimator added the translate-c C to Zig source translation feature (@cImport) label Nov 24, 2019
@andrewrk andrewrk added this to the 0.7.0 milestone Nov 27, 2019
@andrewrk
Copy link
Member

Are you aware of the --verbose-cimport flag? This will probably shed some light.

One of the improvements that the self-hosted translate-c implementation (#1964) does is make these comments rather than usually hidden warnings.

@kavika13
Copy link
Contributor Author

From --verbose-cimport, seems this is semi-intentional since the work to emit this code just isn't done yet, and there's no compiler-side work around in place:

main.c:6:23: warning: TODO handle C InitListExprClass
main.c:5:5: warning: unable to translate function

It does raise the question: should "warnings" be hidden if you don't specify verbose?

@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jan 2, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants