Skip to content

Don't redefine structs that have been forward declared #1866

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

Closed
wants to merge 1 commit into from

Conversation

7Hazard
Copy link

@7Hazard 7Hazard commented Aug 9, 2020

Don't redefine structs that have been forward declared. This will keep track of all struct symbols to know whether a struct has already been defined, similarly to how functions are tracked (seen_function, saw_function).
Resolves #1864

@7Hazard 7Hazard changed the title Resolves #1864 Don't redefine structs that have been forward declared Aug 9, 2020
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. This looks sensible but I'm not sure it's the right approach, we shouldn't be generating forward declarations to begin with, see is_forward_declaration in comp.rs.

I tried to reproduce the issue and I couldn't with a simple example like:

void foo(struct bar*);

typedef struct bar {
    float roll;
    float pitch;
    float yaw;
} bar;

void baz(struct bar*);

So there's clearly something else going on. We should also add a test-case to the test suite to avoid regressing it.

@7Hazard
Copy link
Author

7Hazard commented Aug 9, 2020

I was also hesitant in this approach. I realized the codegen reaches this part when it shouldn't https://github.com/rust-lang/rust-bindgen/blob/master/src/codegen/mod.rs#L1823.

I was able to reproduce the error locally with the example you provided.
This seems to be done as a post-process measure but doesn't take into consideration that the struct was defined in the meantime of the codegen. Im not familiar with the codebase but I will try to find what triggers this.

@emilio
Copy link
Contributor

emilio commented Aug 9, 2020

I was able to reproduce the error locally with the example you provided.

Oh, that's interesting. Which libclang version you have installed?

@7Hazard
Copy link
Author

7Hazard commented Aug 9, 2020

clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

Using the windows installer provided in LLVM's page.

@7Hazard
Copy link
Author

7Hazard commented Aug 10, 2020

So I can't find why exactly what triggers the forward declaration Rust definitions and how to prevent them from triggering if the forward declaration was defined later on by the C header, but I thought I'd share the solution im currently using in my fork.

@bors-servo
Copy link

☔ The latest upstream changes (presumably #2284) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz pvdrz deleted the branch rust-lang:master November 2, 2023 17:50
@pvdrz pvdrz closed this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate definitions with forward declared pointer types
5 participants