diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 88992629..bd29843b 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -923,6 +923,19 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) var accessSpecifier = GetAccessSpecifier(anonymousRecordDecl, matchStar: true); var typeName = GetRemappedTypeName(fieldDecl, context: null, type, out _); + + if (!_config.GenerateDisableRuntimeMarshalling && typeName.Equals("bool", StringComparison.Ordinal)) + { + // bool is not blittable when DisableRuntimeMarshalling is not specified, so we shouldn't use it for structs that may be in P/Invoke signatures + typeName = "byte"; + } + + if (_config.GenerateCompatibleCode && typeName.StartsWith("bool*", StringComparison.Ordinal)) + { + // bool* is not blittable in compat mode, so we shouldn't use it for structs that may be in P/Invoke signatures + typeName = typeName.Replace("bool*", "byte*", StringComparison.Ordinal); + } + var name = GetRemappedCursorName(fieldDecl); var escapedName = EscapeName(name);