From 7bcf3ae945f94b21f2cc3b538b68fae52a2b2598 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Thu, 25 Apr 2024 11:22:43 -0700 Subject: [PATCH] Exclude intrinsics from translation --- .../PInvokeGenerator.VisitDecl.cs | 2 +- .../PInvokeGenerator.cs | 100 +++++++++++------- .../Base/FunctionDeclarationDllImportTest.cs | 5 + .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 11 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ .../FunctionDeclarationDllImportTest.cs | 10 ++ 19 files changed, 228 insertions(+), 40 deletions(-) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 964fbe9c..65465727 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -3966,7 +3966,7 @@ private bool IsConstant(string targetTypeName, Expr initExpr) } } - private bool IsPrimitiveValue(Cursor? cursor, Type type) + private static bool IsPrimitiveValue(Cursor? cursor, Type type) { if (IsType(cursor, type, out var builtinType)) { diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 0242724e..489d314b 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -4539,7 +4539,7 @@ private bool HasVtbl(CXXRecordDecl cxxRecordDecl, out bool hasBaseVtbl) return hasVtbl; } - private bool IsEnumOperator(FunctionDecl functionDecl, string name) + private static bool IsEnumOperator(FunctionDecl functionDecl, string name) { if (name.StartsWith("operator", StringComparison.Ordinal) && ((functionDecl.Parameters.Count == 1) || (functionDecl.Parameters.Count == 2))) { @@ -4586,7 +4586,7 @@ private bool IsExcluded(Cursor cursor, out bool isExcludedByConflictingDefinitio { if (!_isExcluded.TryGetValue(cursor, out var isExcludedValue)) { - isExcludedValue |= (!IsAlwaysIncluded(cursor) && (IsExcludedByConfig(cursor) || IsExcludedByFile(cursor) || IsExcludedByName(cursor, ref isExcludedValue))) ? 0b01u : 0b00u; + isExcludedValue |= (!IsAlwaysIncluded(cursor) && (IsExcludedByConfig(cursor) || IsExcludedByFile(cursor) || IsExcludedByName(cursor, ref isExcludedValue) || IsExcludedByAttributes(cursor))) ? 0b01u : 0b00u; _isExcluded.Add(cursor, isExcludedValue); } isExcludedByConflictingDefinition = (isExcludedValue & 0b10) != 0; @@ -5055,6 +5055,23 @@ bool IsEmptyRecord(RecordDecl recordDecl) return !TryGetUuid(recordDecl, out _); } + + bool IsExcludedByAttributes(Cursor cursor) + { + if (cursor is NamedDecl namedDecl) + { + foreach (var attr in GetAttributesFor(namedDecl)) + { + switch (attr.Kind) + { + case CX_AttrKind_Builtin: + return true; + } + } + } + + return false; + } } private bool IsBaseExcluded(CXXRecordDecl cxxRecordDecl, CXXRecordDecl baseCxxRecordDecl, CXXBaseSpecifier cxxBaseSpecifier, out string baseFieldName) @@ -5239,22 +5256,22 @@ private static bool IsStmtAsWritten(Stmt stmt, Stmt expectedStmt, bool removePar return expr == expectedStmt; } - private bool IsType(Expr expr) + private static bool IsType(Expr expr) where T : Type => IsType(expr, out _); - private bool IsType(Expr expr, [MaybeNullWhen(false)] out T value) + private static bool IsType(Expr expr, [MaybeNullWhen(false)] out T value) where T : Type => IsType(expr, expr.Type, out value); - private bool IsType(ValueDecl valueDecl) + private static bool IsType(ValueDecl valueDecl) where T : Type => IsType(valueDecl, out _); - private bool IsType(ValueDecl typeDecl, [MaybeNullWhen(false)] out T value) + private static bool IsType(ValueDecl typeDecl, [MaybeNullWhen(false)] out T value) where T : Type => IsType(typeDecl, typeDecl.Type, out value); - private bool IsType(Cursor? cursor, Type type) + private static bool IsType(Cursor? cursor, Type type) where T : Type => IsType(cursor, type, out _); - private bool IsType(Cursor? cursor, Type type, [MaybeNullWhen(false)] out T value) + private static bool IsType(Cursor? cursor, Type type, [MaybeNullWhen(false)] out T value) where T : Type { if (type is T t) @@ -5338,36 +5355,36 @@ private bool IsType(Cursor? cursor, Type type, [MaybeNullWhen(false)] out T v return false; } - private bool IsTypeConstantOrIncompleteArray(Expr expr) + private static bool IsTypeConstantOrIncompleteArray(Expr expr) => IsTypeConstantOrIncompleteArray(expr, out _); - private bool IsTypeConstantOrIncompleteArray(Expr expr, [MaybeNullWhen(false)] out ArrayType arrayType) + private static bool IsTypeConstantOrIncompleteArray(Expr expr, [MaybeNullWhen(false)] out ArrayType arrayType) => IsTypeConstantOrIncompleteArray(expr, expr.Type, out arrayType); private bool IsTypeConstantOrIncompleteArray(ValueDecl valueDecl) => IsTypeConstantOrIncompleteArray(valueDecl, out _); - private bool IsTypeConstantOrIncompleteArray(ValueDecl valueDecl, [MaybeNullWhen(false)] out ArrayType arrayType) + private static bool IsTypeConstantOrIncompleteArray(ValueDecl valueDecl, [MaybeNullWhen(false)] out ArrayType arrayType) => IsTypeConstantOrIncompleteArray(valueDecl, valueDecl.Type, out arrayType); - private bool IsTypeConstantOrIncompleteArray(Cursor? cursor, Type type) + private static bool IsTypeConstantOrIncompleteArray(Cursor? cursor, Type type) => IsTypeConstantOrIncompleteArray(cursor, type, out _); - private bool IsTypeConstantOrIncompleteArray(Cursor? cursor, Type type, [MaybeNullWhen(false)] out ArrayType arrayType) + private static bool IsTypeConstantOrIncompleteArray(Cursor? cursor, Type type, [MaybeNullWhen(false)] out ArrayType arrayType) => IsType(cursor, type, out arrayType) && (arrayType is ConstantArrayType or IncompleteArrayType); - private bool IsTypePointerOrReference(Expr expr) + private static bool IsTypePointerOrReference(Expr expr) => IsTypePointerOrReference(expr, expr.Type); - private bool IsTypePointerOrReference(ValueDecl valueDecl) + private static bool IsTypePointerOrReference(ValueDecl valueDecl) => IsTypePointerOrReference(valueDecl, valueDecl.Type); - private bool IsTypePointerOrReference(Cursor? cursor, Type type) + private static bool IsTypePointerOrReference(Cursor? cursor, Type type) => IsType(cursor, type) || IsType(cursor, type); - private bool IsTypeVoid(Cursor? cursor, Type type) + private static bool IsTypeVoid(Cursor? cursor, Type type) => IsType(cursor, type, out var builtinType) && (builtinType.Kind == CXType_Void); @@ -6610,6 +6627,32 @@ private void Visit(IEnumerable cursors) private void Visit(IEnumerable cursors, IEnumerable excludedCursors) => Visit(cursors.Except(excludedCursors)); + private static IEnumerable GetAttributesFor(NamedDecl namedDecl) + { + var declAttrs = namedDecl.HasAttrs + ? namedDecl.Attrs + : Enumerable.Empty(); + + if (namedDecl is FieldDecl fieldDecl) + { + if (IsType(fieldDecl, out var typedefType)) + { + declAttrs = declAttrs.Concat(typedefType.Decl.Attrs); + } + } + else if (namedDecl is RecordDecl recordDecl) + { + var typedefName = recordDecl.TypedefNameForAnonDecl; + + if ((typedefName is not null) && typedefName.HasAttrs) + { + declAttrs = declAttrs.Concat(typedefName.Attrs); + } + } + + return declAttrs; + } + private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform = false, bool isTestOutput = false) { var outputBuilder = isTestOutput ? _testOutputBuilder : _outputBuilder; @@ -6625,30 +6668,9 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform = if (!isTestOutput) { - var declAttrs = namedDecl.HasAttrs - ? namedDecl.Attrs - : Enumerable.Empty(); - - if (namedDecl is FieldDecl fieldDecl) - { - if (IsType(fieldDecl, out var typedefType)) - { - declAttrs = declAttrs.Concat(typedefType.Decl.Attrs); - } - } - else if (namedDecl is RecordDecl recordDecl) - { - var typedefName = recordDecl.TypedefNameForAnonDecl; - - if ((typedefName is not null) && typedefName.HasAttrs) - { - declAttrs = declAttrs.Concat(typedefName.Attrs); - } - } - var obsoleteEmitted = false; - foreach (var attr in declAttrs) + foreach (var attr in GetAttributesFor(namedDecl)) { switch (attr.Kind) { diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/FunctionDeclarationDllImportTest.cs index dede50f2..763a04f9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/FunctionDeclarationDllImportTest.cs @@ -78,6 +78,9 @@ public abstract class FunctionDeclarationDllImportTest : PInvokeGeneratorTest [Test] public Task VarargsTest() => VarargsTestImpl(); + [Test] + public Task IntrinsicsTest() => IntrinsicsTestImpl(); + protected abstract Task BasicTestImpl(); protected abstract Task ArrayParameterTestImpl(); @@ -113,4 +116,6 @@ public abstract class FunctionDeclarationDllImportTest : PInvokeGeneratorTest protected abstract Task SourceLocationTestImpl(); protected abstract Task VarargsTestImpl(); + + protected abstract Task IntrinsicsTestImpl(); } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/FunctionDeclarationDllImportTest.cs index 6a976236..0b969f31 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/FunctionDeclarationDllImportTest.cs @@ -399,4 +399,14 @@ public static partial class Methods } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/FunctionDeclarationDllImportTest.cs index 765ce399..5b04ad84 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/FunctionDeclarationDllImportTest.cs @@ -416,4 +416,14 @@ public static partial class Methods return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(InputContents, ExpectedOutputContents); } + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationDllImportTest.cs index 8e082149..e738ed82 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationDllImportTest.cs @@ -398,4 +398,14 @@ public static partial class Methods } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationDllImportTest.cs index 0c5f180e..4c72b3f4 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationDllImportTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using NUnit.Framework; @@ -415,4 +416,14 @@ public static partial class Methods return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); } + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/FunctionDeclarationDllImportTest.cs index d989b804..f79b003e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/FunctionDeclarationDllImportTest.cs @@ -398,4 +398,14 @@ public static partial class Methods } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/FunctionDeclarationDllImportTest.cs index 7dd8e3c7..522c1ff5 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/FunctionDeclarationDllImportTest.cs @@ -415,4 +415,14 @@ public static partial class Methods return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents); } + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationDllImportTest.cs index e079637d..98c598ff 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationDllImportTest.cs @@ -398,4 +398,14 @@ public static partial class Methods } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationDllImportTest.cs index 4fbeb1e4..2ebba7ad 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationDllImportTest.cs @@ -415,4 +415,14 @@ public static partial class Methods return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(InputContents, ExpectedOutputContents); } + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/FunctionDeclarationDllImportTest.cs index d1ff401d..4df425ee 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/FunctionDeclarationDllImportTest.cs index 28508ac3..a6f62ac8 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationDllImportTest.cs index ad2a82a8..8ef79a6b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationDllImportTest.cs index 79a1ea0d..39c1c6fa 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/FunctionDeclarationDllImportTest.cs index ce5041aa..d3222b5d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/FunctionDeclarationDllImportTest.cs index 43f39925..83365118 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationDllImportTest.cs index ed3a3bad..7816a51b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationDllImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationDllImportTest.cs index 613f479f..6258e963 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationDllImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationDllImportTest.cs @@ -451,4 +451,14 @@ protected override Task SourceLocationTestImpl() } protected override Task VarargsTestImpl() => Task.CompletedTask; + + protected override Task IntrinsicsTestImpl() + { + const string InputContents = @"extern ""C"" void __builtin_cpu_init(); +#pragma intrinsic(__builtin_cpu_init)"; + + const string ExpectedOutputContents = @""; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents); + } }