Added support for #[repr(transparent)]

This commit is contained in:
Vincent Esche
2018-08-03 02:13:14 +02:00
committed by Ryan Hunt
parent 090b8154dd
commit 5e6d58dfe3
8 changed files with 183 additions and 8 deletions
+24
View File
@@ -0,0 +1,24 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct DummyStruct DummyStruct;
typedef DummyStruct TransparentComplexWrappingStructTuple;
typedef uint32_t TransparentPrimitiveWrappingStructTuple;
typedef DummyStruct TransparentComplexWrappingStructure;
typedef uint32_t TransparentPrimitiveWrappingStructure;
typedef DummyStruct TransparentComplexWrapper_i32;
typedef uint32_t TransparentPrimitiveWrapper_i32;
void root(TransparentComplexWrappingStructTuple a,
TransparentPrimitiveWrappingStructTuple b,
TransparentComplexWrappingStructure c,
TransparentPrimitiveWrappingStructure d,
TransparentComplexWrapper_i32 e,
TransparentPrimitiveWrapper_i32 f);
+24
View File
@@ -0,0 +1,24 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
struct DummyStruct;
typedef struct DummyStruct TransparentComplexWrappingStructTuple;
typedef uint32_t TransparentPrimitiveWrappingStructTuple;
typedef struct DummyStruct TransparentComplexWrappingStructure;
typedef uint32_t TransparentPrimitiveWrappingStructure;
typedef struct DummyStruct TransparentComplexWrapper_i32;
typedef uint32_t TransparentPrimitiveWrapper_i32;
void root(TransparentComplexWrappingStructTuple a,
TransparentPrimitiveWrappingStructTuple b,
TransparentComplexWrappingStructure c,
TransparentPrimitiveWrappingStructure d,
TransparentComplexWrapper_i32 e,
TransparentPrimitiveWrapper_i32 f);
+24
View File
@@ -0,0 +1,24 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct DummyStruct DummyStruct;
typedef DummyStruct TransparentComplexWrappingStructTuple;
typedef uint32_t TransparentPrimitiveWrappingStructTuple;
typedef DummyStruct TransparentComplexWrappingStructure;
typedef uint32_t TransparentPrimitiveWrappingStructure;
typedef DummyStruct TransparentComplexWrapper_i32;
typedef uint32_t TransparentPrimitiveWrapper_i32;
void root(TransparentComplexWrappingStructTuple a,
TransparentPrimitiveWrappingStructTuple b,
TransparentComplexWrappingStructure c,
TransparentPrimitiveWrappingStructure d,
TransparentComplexWrapper_i32 e,
TransparentPrimitiveWrapper_i32 f);
+29
View File
@@ -0,0 +1,29 @@
#include <cstdint>
#include <cstdlib>
struct DummyStruct;
using TransparentComplexWrappingStructTuple = DummyStruct;
using TransparentPrimitiveWrappingStructTuple = uint32_t;
using TransparentComplexWrappingStructure = DummyStruct;
using TransparentPrimitiveWrappingStructure = uint32_t;
template<typename T>
using TransparentComplexWrapper = DummyStruct;
template<typename T>
using TransparentPrimitiveWrapper = uint32_t;
extern "C" {
void root(TransparentComplexWrappingStructTuple a,
TransparentPrimitiveWrappingStructTuple b,
TransparentComplexWrappingStructure c,
TransparentPrimitiveWrappingStructure d,
TransparentComplexWrapper<int32_t> e,
TransparentPrimitiveWrapper<int32_t> f);
} // extern "C"
+41
View File
@@ -0,0 +1,41 @@
struct DummyStruct;
// Transparent struct tuple wrapping a struct.
#[repr(transparent)]
struct TransparentComplexWrappingStructTuple(DummyStruct);
// Transparent struct tuple wrapping a primitive.
#[repr(transparent)]
struct TransparentPrimitiveWrappingStructTuple(u32);
// Transparent structure wrapping a struct.
#[repr(transparent)]
struct TransparentComplexWrappingStructure { only_field: DummyStruct }
// Transparent structure wrapping a primitive.
#[repr(transparent)]
struct TransparentPrimitiveWrappingStructure { only_field: u32 }
// Transparent struct wrapper with a marker wrapping a struct.
#[repr(transparent)]
struct TransparentComplexWrapper<T> {
only_non_zero_sized_field: DummyStruct,
marker: PhantomData<T>,
}
// Transparent struct wrapper with a marker wrapping a primitive.
#[repr(transparent)]
struct TransparentPrimitiveWrapper<T> {
only_non_zero_sized_field: u32,
marker: PhantomData<T>,
}
#[no_mangle]
pub extern "C" fn root(
a: TransparentComplexWrappingStructTuple,
b: TransparentPrimitiveWrappingStructTuple,
c: TransparentComplexWrappingStructure,
d: TransparentPrimitiveWrappingStructure,
e: TransparentComplexWrapper<i32>,
f: TransparentPrimitiveWrapper<i32>,
) { }