| author | |
| committer | |
| log | 79a620d617aaadbdf39a2536f3ac85ef1f6fb53e |
| tree | 476f22613d3197645cabd7f70b2cf1b96bdb91c8 |
| parent | 70437354c02125f6a6dd36d53b5edb8f5cd193c2 |
Also add a static_assert to catch future alignment mismatches on this type, and
reflect recent layout changes in the Zig bindings.3 files changed, 14 insertions(+), 10 deletions(-)
src/clang.zig+2-2| ... | @@ -63,8 +63,8 @@ pub const APValueKind = enum(c_int) { | ... | @@ -63,8 +63,8 @@ pub const APValueKind = enum(c_int) { |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | pub const APValue = extern struct { | 65 | pub const APValue = extern struct { |
| 66 | Kind: APValueKind, | 66 | Kind: APValueKind align(if (builtin.cpu.arch == .x86 and builtin.os.tag != .windows) 4 else 8), |
| 67 | Data: if (builtin.os.tag == .windows and (builtin.abi == .msvc or builtin.abi == .itanium)) [52]u8 else [68]u8, | 67 | Data: if (builtin.cpu.arch == .x86 and builtin.os.tag != .windows) [44]u8 else [52]u8, |
| 68 | 68 | ||
| 69 | pub const getKind = ZigClangAPValue_getKind; | 69 | pub const getKind = ZigClangAPValue_getKind; |
| 70 | extern fn ZigClangAPValue_getKind(*const APValue) APValueKind; | 70 | extern fn ZigClangAPValue_getKind(*const APValue) APValueKind; |
src/zig_clang.cpp+1| ... | @@ -2329,6 +2329,7 @@ static_assert((clang::UnaryExprOrTypeTrait)ZigClangUnaryExprOrTypeTrait_Kind::Zi | ... | @@ -2329,6 +2329,7 @@ static_assert((clang::UnaryExprOrTypeTrait)ZigClangUnaryExprOrTypeTrait_Kind::Zi |
| 2329 | static_assert((clang::UnaryExprOrTypeTrait)ZigClangUnaryExprOrTypeTrait_Kind::ZigClangUnaryExprOrTypeTrait_KindOpenMPRequiredSimdAlign == clang::UnaryExprOrTypeTrait::UETT_OpenMPRequiredSimdAlign, ""); | 2329 | static_assert((clang::UnaryExprOrTypeTrait)ZigClangUnaryExprOrTypeTrait_Kind::ZigClangUnaryExprOrTypeTrait_KindOpenMPRequiredSimdAlign == clang::UnaryExprOrTypeTrait::UETT_OpenMPRequiredSimdAlign, ""); |
| 2330 | 2330 | ||
| 2331 | static_assert(sizeof(ZigClangAPValue) == sizeof(clang::APValue), ""); | 2331 | static_assert(sizeof(ZigClangAPValue) == sizeof(clang::APValue), ""); |
| 2332 | static_assert(alignof(ZigClangAPValue) == alignof(clang::APValue), ""); | ||
| 2332 | 2333 | ||
| 2333 | static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), ""); | 2334 | static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), ""); |
| 2334 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { | 2335 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
src/zig_clang.h+11-8| ... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
| 9 | #define ZIG_ZIG_CLANG_H | 9 | #define ZIG_ZIG_CLANG_H |
| 10 | 10 | ||
| 11 | #include <inttypes.h> | 11 | #include <inttypes.h> |
| 12 | #include <stdalign.h> | ||
| 12 | #include <stdbool.h> | 13 | #include <stdbool.h> |
| 13 | #include <stddef.h> | 14 | #include <stddef.h> |
| 14 | 15 | ||
| ... | @@ -65,16 +66,18 @@ enum ZigClangAPValueKind { | ... | @@ -65,16 +66,18 @@ enum ZigClangAPValueKind { |
| 65 | ZigClangAPValueAddrLabelDiff, | 66 | ZigClangAPValueAddrLabelDiff, |
| 66 | }; | 67 | }; |
| 67 | 68 | ||
| 68 | struct ZigClangAPValue { | 69 | #if defined(__i386__) && !defined(_WIN32) |
| 69 | enum ZigClangAPValueKind Kind; | 70 | # define ZIG_CLANG_APVALUE_SIZE 44 |
| 70 | // experimentally-derived size of clang::APValue::DataType | 71 | # define ZIG_CLANG_APVALUE_ALIGN 4 |
| 71 | #if defined(_WIN32) && defined(_MSC_VER) | ||
| 72 | char Data[52]; | ||
| 73 | #elif defined(__i386__) && !defined(_WIN32) | ||
| 74 | char Data[44]; | ||
| 75 | #else | 72 | #else |
| 76 | char Data[52]; | 73 | # define ZIG_CLANG_APVALUE_SIZE 52 |
| 74 | # define ZIG_CLANG_APVALUE_ALIGN 8 | ||
| 77 | #endif | 75 | #endif |
| 76 | |||
| 77 | struct alignas(ZIG_CLANG_APVALUE_ALIGN) ZigClangAPValue { | ||
| 78 | enum ZigClangAPValueKind Kind; | ||
| 79 | // experimentally-derived size of clang::APValue::DataType | ||
| 80 | char Data[ZIG_CLANG_APVALUE_SIZE]; | ||
| 78 | }; | 81 | }; |
| 79 | 82 | ||
| 80 | struct ZigClangExprEvalResult { | 83 | struct ZigClangExprEvalResult { |