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

Bug nesting const generics #761

Closed
jorendorff opened this issue May 11, 2022 · 0 comments
Closed

Bug nesting const generics #761

jorendorff opened this issue May 11, 2022 · 0 comments

Comments

@jorendorff
Copy link
Contributor

The test case below generates broken C code.

// Propagating const arguments through generics that use generics.

#[repr(C)]
struct Inner<N: usize> {
    bytes: [u8; N],
}

#[repr(C)]
struct Outer<N: usize> {
    inner: Inner<N>, // don't declare two different structs named `Inner_N`
}

#[no_mangle]
pub extern "C" fn one() -> Outer<1> {
    Outer { inner: Inner { bytes: [0] } }
}

#[no_mangle]
pub extern "C" fn two() -> Outer<2> {
    Outer { inner: Inner { bytes: [0, 0] } }
}

cargo run -- --lang c --style tag $FILE produces this:

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct Inner_N {
  uint8_t bytes[N];
};

struct Outer_1 {
  struct Inner_N inner;
};

struct Outer_2 {
  struct Inner_N inner;
};

struct Outer_1 one(void);

struct Outer_2 two(void);

The corresponding thing works fine with type parameters, so there must be something I failed to hook up in #759, or maybe we aren't modeling the value namespace at all. Filing the bug because I don't have time to look right now. I should have time in the next few days, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant