Add a test that demonstrates Style::Tag can emit structures with incorrect sizes in C.
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
12248c2fef
commit
8048748419
@@ -157,6 +157,30 @@ typedef struct {
|
||||
};
|
||||
} I;
|
||||
|
||||
enum P_Tag {
|
||||
P0,
|
||||
P1,
|
||||
};
|
||||
typedef uint8_t P_Tag;
|
||||
|
||||
typedef struct {
|
||||
uint8_t _0;
|
||||
} P0_Body;
|
||||
|
||||
typedef struct {
|
||||
uint8_t _0;
|
||||
uint8_t _1;
|
||||
uint8_t _2;
|
||||
} P1_Body;
|
||||
|
||||
typedef struct {
|
||||
P_Tag tag;
|
||||
union {
|
||||
P0_Body p0;
|
||||
P1_Body p1;
|
||||
};
|
||||
} P;
|
||||
|
||||
void root(Opaque *opaque,
|
||||
A a,
|
||||
B b,
|
||||
@@ -172,4 +196,12 @@ void root(Opaque *opaque,
|
||||
L l,
|
||||
M m,
|
||||
N n,
|
||||
O o);
|
||||
O o,
|
||||
P p);
|
||||
|
||||
#include <stddef.h>
|
||||
#include "testing-helpers.h"
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1");
|
||||
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
|
||||
|
||||
@@ -217,6 +217,36 @@ typedef struct {
|
||||
};
|
||||
} I;
|
||||
|
||||
enum P_Tag
|
||||
#ifdef __cplusplus
|
||||
: uint8_t
|
||||
#endif // __cplusplus
|
||||
{
|
||||
P0,
|
||||
P1,
|
||||
};
|
||||
#ifndef __cplusplus
|
||||
typedef uint8_t P_Tag;
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef struct {
|
||||
uint8_t _0;
|
||||
} P0_Body;
|
||||
|
||||
typedef struct {
|
||||
uint8_t _0;
|
||||
uint8_t _1;
|
||||
uint8_t _2;
|
||||
} P1_Body;
|
||||
|
||||
typedef struct {
|
||||
P_Tag tag;
|
||||
union {
|
||||
P0_Body p0;
|
||||
P1_Body p1;
|
||||
};
|
||||
} P;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
@@ -236,8 +266,16 @@ void root(Opaque *opaque,
|
||||
L l,
|
||||
M m,
|
||||
N n,
|
||||
O o);
|
||||
O o,
|
||||
P p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
|
||||
#include <stddef.h>
|
||||
#include "testing-helpers.h"
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1");
|
||||
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
|
||||
|
||||
@@ -217,6 +217,36 @@ struct I {
|
||||
};
|
||||
};
|
||||
|
||||
enum P_Tag
|
||||
#ifdef __cplusplus
|
||||
: uint8_t
|
||||
#endif // __cplusplus
|
||||
{
|
||||
P0,
|
||||
P1,
|
||||
};
|
||||
#ifndef __cplusplus
|
||||
typedef uint8_t P_Tag;
|
||||
#endif // __cplusplus
|
||||
|
||||
struct P0_Body {
|
||||
uint8_t _0;
|
||||
};
|
||||
|
||||
struct P1_Body {
|
||||
uint8_t _0;
|
||||
uint8_t _1;
|
||||
uint8_t _2;
|
||||
};
|
||||
|
||||
struct P {
|
||||
enum P_Tag tag;
|
||||
union {
|
||||
struct P0_Body p0;
|
||||
struct P1_Body p1;
|
||||
};
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
@@ -236,8 +266,16 @@ void root(struct Opaque *opaque,
|
||||
enum L l,
|
||||
M m,
|
||||
enum N n,
|
||||
O o);
|
||||
O o,
|
||||
struct P p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
|
||||
#include <stddef.h>
|
||||
#include "testing-helpers.h"
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1");
|
||||
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
|
||||
|
||||
@@ -121,6 +121,12 @@ enum O {
|
||||
o4,
|
||||
}
|
||||
|
||||
#[repr(C, u8)]
|
||||
enum P {
|
||||
P0(u8),
|
||||
P1(u8, u8, u8),
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(
|
||||
opaque: *mut Opaque,
|
||||
@@ -139,5 +145,6 @@ pub extern "C" fn root(
|
||||
m: M,
|
||||
n: N,
|
||||
o: O,
|
||||
p: P,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
trailer = """
|
||||
#include <stddef.h>
|
||||
#include "testing-helpers.h"
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0");
|
||||
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1");
|
||||
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
|
||||
"""
|
||||
Reference in New Issue
Block a user