-
Notifications
You must be signed in to change notification settings - Fork 697
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
Types can end up in the wrong namespace #2556
Comments
I commented on #2543 with some stuff that I found at a glance but I don't think it necessarily causes this bug... |
@glandium I also needed |
I'm fairly confused at #2543. It only sorts the direct children of a cursor, how does it deal with C++ namespaces or other cursors with nested children for which we return |
Another probably more relevant data point. If I remove the |
We're probably relying on seeing a declaration before a template instantiation and somehow bindgen is getting the sorting wrong because of the |
See one of the many ways to make it work mentioned in OP ;) |
BTW, I should mention that replacing the |
Here's an actually reduced test-case. Still multiple headers because of the nature of the issue: reduced.tar.gz To reproduce:
The |
Further reduced: reduced.tar.gz
Actual output: /* automatically generated by rust-bindgen 0.66.0 */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct foo_nsSize {
pub width: ::std::os::raw::c_int,
pub height: ::std::os::raw::c_int,
}
extern "C" {
#[link_name = "\u{1}_ZN3fooL22kFallbackIntrinsicSizeE"]
pub static foo_kFallbackIntrinsicSize: foo_nsSize;
} Expected output: /* automatically generated by rust-bindgen 0.66.0 */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct nsSize {
pub width: ::std::os::raw::c_int,
pub height: ::std::os::raw::c_int,
}
extern "C" {
#[link_name = "\u{1}_ZN3fooL22kFallbackIntrinsicSizeE"]
pub static foo_kFallbackIntrinsicSize: nsSize;
} |
Not a surprise of course, but the sorting is going rather wrong:
I don't think the source order comparison is working right to begin with, it only deals with one level of includes? In the case of |
The other thing I don't understand is why do we need to do this sorting at all? The original sorting from clang looks right. |
This disables (hopefully temporarily) source order sorting, for causing correctness regressions like rust-lang#2556. Fixes rust-lang#2556.
Now if you have this #define VAR 1
#undef VAR
const int VAR = 2; it would generate |
@reitermarkus why do we need the var to be sorted correctly relatively to the macro? The var is already correctly macro-expanded etc, that's the only reason bindgen can deal with token pasting etc. The macro information that clang provides should be treated probably rather separately to everything else. And that still would work for a test-case like the one you pasted, right? In any case the source order sorting as implemented today is clearly incorrect. I ran out of time to fix it for the day, so I sent a PR to disable temporarily, see #2558. I think that's the best course of action for now until it can be adapted to deal with multiple layers of includes properly. |
In #2369, it is treated separately. The issue is, macros are parsed first, so in codegen macros are also generated first. And we generate constants for variable-like macros as well as for real constants. |
Ok, seems those conflicts should be dealt with at codegen time? Or am I missing something? Or, rather, there's no reason we couldn't run codegen for macro-generated constants later, to "favor" real constants |
Then this const int VAR = 1;
#define VAR 2 would wrongly generate |
I noticed this in 83f729f but decided to ignore it for some reason 🤔. This is starting to sound like you need to topologically sort the cursors based on the partial order defined there instead of just sorting them in a binary way. In that way any cursor that appears before another in the list is guaranteed to not depend on the latter. |
* clang: Clean up source order sorting. This doesn't change behavior but is easier to debug and reason about (because you have the relevant cursors there). * clang: Disable source order sorting for now. This disables (hopefully temporarily) source order sorting, for causing correctness regressions like #2556. Fixes #2556. * tests: Add a test for #2556 * Remove merge artifact * Update clang.rs --------- Co-authored-by: Christian Poveda Ruiz <[email protected]>
Can you spin a 0.66.1 release with the fix? |
(there are failing tests on CI, though) |
Ugh I think that's because the clang 5 and 9 tests needed to be reverted too. I'll take a look. The PR for |
This is a regression from 83f729f
Input C/C++ Header
I'm sorry this is not reduced as much as possible, but it's already significantly reduced. The problem does not happen using the output of --dump-preprocessed-input (it does require multiple separate headers, and even worse, it requires that some of them are included multiple times)
The complete set of files involved in this somehow reduced testcase is: https://drive.google.com/file/d/1vldgLGgcslyeUTlcHzMd4r0WVZNY2Wht/view?usp=sharing
Bindgen Invocation
Assuming the
testcase.tar.gz
archive is extracted to/tmp/testcase
, run the cli with(using clang 16, I don't know for sure whether the command works with older versions, I know for sure it doesn't work with clang 11, because I have that in a corner)
Actual Results
The output contains the nsSize type in the root::mozilla namespace, although the type is defined in the root namespace.
There are many ways to make this disappear:
--allowlist-type nsSimpleContentList
constexpr nsSize dummy(0, 0);
abovenamespace mozilla
(because yes, that's where the bogus namespace comes from)mozilla-config.h
,nsStyleStruct.h
,LayoutConstants.h
andmozilla/GeckoBindings.h
, and using that instead of passing those files on the command line.The text was updated successfully, but these errors were encountered: