From 22cc7af5e1e2ac1cc54181d1501a8d472724ca8a Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 26 Nov 2024 13:13:08 +0100 Subject: [PATCH 1/5] C#: Only extract Public and Protected members from reference assemblies. --- .../SymbolExtensions.cs | 35 +++++++++++++++++++ .../Entities/Method.cs | 2 +- .../Entities/Types/Type.cs | 14 ++++---- .../Extractor/Analyser.cs | 2 +- .../Extractor/Extractor.cs | 1 - 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs b/csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs index 72c45b797d8a..afdd90428314 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs @@ -642,5 +642,40 @@ public static AnnotatedTypeSymbol GetType(this Context cx, Microsoft.CodeAnalysi /// public static IEnumerable GetAnnotatedTypeArguments(this INamedTypeSymbol symbol) => symbol.TypeArguments.Zip(symbol.TypeArgumentNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a)); + + /// + /// Returns true if the symbol is public, protected or protected internal. + /// + public static bool IsPublicOrProtected(this ISymbol symbol) => + symbol.DeclaredAccessibility == Accessibility.Public + || symbol.DeclaredAccessibility == Accessibility.Protected + || symbol.DeclaredAccessibility == Accessibility.ProtectedOrInternal; + + /// + /// Returns true if the given symbol should be extracted. + /// + public static bool ShouldExtractSymbol(this ISymbol symbol) + { + // Extract all source symbols and public/protected metadata symbols. + if (symbol.Locations.Any(x => !x.IsInMetadata) || symbol.IsPublicOrProtected()) + { + return true; + } + if (symbol is IMethodSymbol method) + { + return method.ExplicitInterfaceImplementations.Any(m => m.ContainingType.DeclaredAccessibility == Accessibility.Public); + } + if (symbol is IPropertySymbol property) + { + return property.ExplicitInterfaceImplementations.Any(m => m.ContainingType.DeclaredAccessibility == Accessibility.Public); + } + return false; + } + + /// + /// Returns the symbols that should be extracted. + /// + public static IEnumerable ExtractionCandidates(this IEnumerable symbols) where T : ISymbol => + symbols.Where(symbol => symbol.ShouldExtractSymbol()); } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs index 6890ca490847..6ba5cca01cf6 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs @@ -101,7 +101,7 @@ public void Overrides(TextWriter trapFile) } } - if (Symbol.OverriddenMethod is not null) + if (Symbol.OverriddenMethod is not null && Symbol.OverriddenMethod.ShouldExtractSymbol()) { trapFile.overrides(this, Method.Create(Context, Symbol.OverriddenMethod)); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs index 56382923a480..fb7596961abd 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs @@ -225,7 +225,7 @@ private void ExtractParametersForDelegateLikeType(TextWriter trapFile, IMethodSy } /// - /// Called to extract all members and nested types. + /// Called to extract members and nested types. /// This is called on each member of a namespace, /// in either source code or an assembly. /// @@ -236,7 +236,7 @@ public void ExtractRecursive() Context.BindComments(this, l); } - foreach (var member in Symbol.GetMembers()) + foreach (var member in Symbol.GetMembers().ExtractionCandidates()) { switch (member.Kind) { @@ -262,16 +262,16 @@ public void PopulateGenerics() var members = new List(); - foreach (var member in Symbol.GetMembers()) + foreach (var member in Symbol.GetMembers().ExtractionCandidates()) members.Add(member); - foreach (var member in Symbol.GetTypeMembers()) + foreach (var member in Symbol.GetTypeMembers().ExtractionCandidates()) members.Add(member); // Mono extractor puts all BASE interface members as members of the current interface. if (Symbol.TypeKind == TypeKind.Interface) { - foreach (var baseInterface in Symbol.Interfaces) + foreach (var baseInterface in Symbol.Interfaces.ExtractionCandidates()) { foreach (var member in baseInterface.GetMembers()) members.Add(member); @@ -285,10 +285,10 @@ public void PopulateGenerics() Context.CreateEntity(member); } - if (Symbol.BaseType is not null) + if (Symbol.BaseType is not null && Symbol.BaseType.ShouldExtractSymbol()) Create(Context, Symbol.BaseType).PopulateGenerics(); - foreach (var i in Symbol.Interfaces) + foreach (var i in Symbol.Interfaces.ExtractionCandidates()) { Create(Context, i).PopulateGenerics(); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs index b839d2c976a3..3ea99a0d772c 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs @@ -269,7 +269,7 @@ private static void AnalyseNamespace(Context cx, INamespaceSymbol ns) AnalyseNamespace(cx, memberNamespace); } - foreach (var memberType in ns.GetTypeMembers()) + foreach (var memberType in ns.GetTypeMembers().ExtractionCandidates()) { Entities.Type.Create(cx, memberType).ExtractRecursive(); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs index 50f673a71581..3c01893dd89c 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs @@ -549,7 +549,6 @@ private static ExitCode AnalyseTracing( compilerArguments.CompilationOptions .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) .WithStrongNameProvider(new DesktopStrongNameProvider(compilerArguments.KeyFileSearchPaths)) - .WithMetadataImportOptions(MetadataImportOptions.All) ); }, (compilation, options) => analyser.EndInitialize(compilerArguments, options, compilation, cwd, args), From 1331235e338542af88357a72f77dd43830ac6691 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Fri, 29 Nov 2024 11:29:42 +0100 Subject: [PATCH 2/5] C#: Update expected test output. --- .../conversion/operator/Operator.expected | 3 -- .../conversion/reftype/RefType.expected | 6 ---- .../csharp9/FunctionPointer.expected | 35 ------------------- .../test/library-tests/tuples/tuples.expected | 8 ----- 4 files changed, 52 deletions(-) diff --git a/csharp/ql/test/library-tests/conversion/operator/Operator.expected b/csharp/ql/test/library-tests/conversion/operator/Operator.expected index dd11565ad2a9..b0dcfc54260d 100644 --- a/csharp/ql/test/library-tests/conversion/operator/Operator.expected +++ b/csharp/ql/test/library-tests/conversion/operator/Operator.expected @@ -21,7 +21,6 @@ | Int32 | Decimal | | Int32 | Index | | Int32 | Int128 | -| Int32 | MetadataToken | | Int32 | NFloat | | Int64 | Decimal | | Int64 | Int128 | @@ -29,7 +28,6 @@ | IntPtr | Int128 | | IntPtr | NFloat | | Memory`1 | ReadOnlyMemory | -| MetadataToken | Int32 | | NFloat | Double | | SByte | Decimal | | SByte | Half | @@ -59,4 +57,3 @@ | UIntPtr | Int128 | | UIntPtr | NFloat | | UIntPtr | UInt128 | -| UnixFileMode | Nullable | diff --git a/csharp/ql/test/library-tests/conversion/reftype/RefType.expected b/csharp/ql/test/library-tests/conversion/reftype/RefType.expected index ab433d458963..ff2c9da9ea39 100644 --- a/csharp/ql/test/library-tests/conversion/reftype/RefType.expected +++ b/csharp/ql/test/library-tests/conversion/reftype/RefType.expected @@ -183,8 +183,6 @@ | IReadOnlyList | dynamic | | Int16[] | Object | | Int16[] | dynamic | -| Int32[,] | Object | -| Int32[,] | dynamic | | Int32[] | Object | | Int32[] | dynamic | | Int64[] | Object | @@ -223,8 +221,6 @@ | T5 | C1 | | T5 | Object | | T5 | dynamic | -| UInt16[][] | Object | -| UInt16[][] | dynamic | | UInt32[] | Object | | UInt32[] | dynamic | | UInt64[] | Object | @@ -283,7 +279,6 @@ | null | IReadOnlyList | | null | IReadOnlyList | | null | Int16[] | -| null | Int32[,] | | null | Int32[] | | null | Int64[] | | null | Object | @@ -294,7 +289,6 @@ | null | T4 | | null | T4[] | | null | T5 | -| null | UInt16[][] | | null | UInt32[] | | null | UInt64[] | | null | dynamic | diff --git a/csharp/ql/test/library-tests/csharp9/FunctionPointer.expected b/csharp/ql/test/library-tests/csharp9/FunctionPointer.expected index d2617be088bc..1bf279341ce8 100644 --- a/csharp/ql/test/library-tests/csharp9/FunctionPointer.expected +++ b/csharp/ql/test/library-tests/csharp9/FunctionPointer.expected @@ -1,68 +1,33 @@ type | file://:0:0:0:0 | delegate* default | B | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | A | DefaultCallingConvention | -| file://:0:0:0:0 | delegate* default | Void | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | ref int | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | readonly int | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | Void* | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | int | DefaultCallingConvention | -| file://:0:0:0:0 | delegate* default | Void | DefaultCallingConvention | -| file://:0:0:0:0 | delegate* default | Void | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | int | DefaultCallingConvention | | file://:0:0:0:0 | delegate* default | int* | DefaultCallingConvention | -| file://:0:0:0:0 | delegate* default | object | DefaultCallingConvention | | file://:0:0:0:0 | delegate* stdcall | Void | StdCallCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | int | UnmanagedCallingConvention | | file://:0:0:0:0 | delegate* unmanaged | int | UnmanagedCallingConvention | | file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | -| file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | | file://:0:0:0:0 | delegate* unmanaged | Void | UnmanagedCallingConvention | unmanagedCallingConvention parameter | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | A | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | B | -| file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | ref byte! | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | ref int! | | file://:0:0:0:0 | delegate* default | 1 | file://:0:0:0:0 | `1 | out object? | | file://:0:0:0:0 | delegate* default | 2 | file://:0:0:0:0 | `2 | readonly int! | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | ref int! | | file://:0:0:0:0 | delegate* default | 1 | file://:0:0:0:0 | `1 | out object? | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | int*! | -| file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | IntPtr! | -| file://:0:0:0:0 | delegate* default | 1 | file://:0:0:0:0 | `1 | ref byte! | -| file://:0:0:0:0 | delegate* default | 2 | file://:0:0:0:0 | `2 | PortableTailCallFrame*! | -| file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | object | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | T | | file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | Void*! | -| file://:0:0:0:0 | delegate* default | 0 | file://:0:0:0:0 | | Void*! | | file://:0:0:0:0 | delegate* stdcall | 0 | file://:0:0:0:0 | | ref int! | | file://:0:0:0:0 | delegate* stdcall | 1 | file://:0:0:0:0 | `1 | out object? | | file://:0:0:0:0 | delegate* stdcall | 2 | file://:0:0:0:0 | `2 | T | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | byte*! | -| file://:0:0:0:0 | delegate* unmanaged | 1 | file://:0:0:0:0 | `1 | int! | -| file://:0:0:0:0 | delegate* unmanaged | 2 | file://:0:0:0:0 | `2 | byte! | -| file://:0:0:0:0 | delegate* unmanaged | 3 | file://:0:0:0:0 | `3 | long! | -| file://:0:0:0:0 | delegate* unmanaged | 4 | file://:0:0:0:0 | `4 | long! | -| file://:0:0:0:0 | delegate* unmanaged | 5 | file://:0:0:0:0 | `5 | EVENT_FILTER_DESCRIPTOR*! | -| file://:0:0:0:0 | delegate* unmanaged | 6 | file://:0:0:0:0 | `6 | Void*! | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | char*! | -| file://:0:0:0:0 | delegate* unmanaged | 1 | file://:0:0:0:0 | `1 | IntPtr! | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | int! | -| file://:0:0:0:0 | delegate* unmanaged | 1 | file://:0:0:0:0 | `1 | PosixSignal! | | file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | IntPtr! | | file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | IntPtr! | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | NoGCRegionCallbackFinalizerWorkItem*! | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | Void*! | -| file://:0:0:0:0 | delegate* unmanaged | 1 | file://:0:0:0:0 | `1 | byte*! | -| file://:0:0:0:0 | delegate* unmanaged | 0 | file://:0:0:0:0 | | Void*! | -| file://:0:0:0:0 | delegate* unmanaged | 1 | file://:0:0:0:0 | `1 | Void*! | -| file://:0:0:0:0 | delegate* unmanaged | 2 | file://:0:0:0:0 | `2 | Void*! | -| file://:0:0:0:0 | delegate* unmanaged | 3 | file://:0:0:0:0 | `3 | GCConfigurationType! | -| file://:0:0:0:0 | delegate* unmanaged | 4 | file://:0:0:0:0 | `4 | long! | invocation | FunctionPointer.cs:17:21:17:43 | function pointer call | | FunctionPointer.cs:23:13:23:44 | function pointer call | diff --git a/csharp/ql/test/library-tests/tuples/tuples.expected b/csharp/ql/test/library-tests/tuples/tuples.expected index c2042bfb14ac..cb39eb0ca3b8 100644 --- a/csharp/ql/test/library-tests/tuples/tuples.expected +++ b/csharp/ql/test/library-tests/tuples/tuples.expected @@ -8,13 +8,11 @@ members2 | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | Equals(object, IEqualityComparer) | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | GetHashCode() | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | GetHashCode(IEqualityComparer) | -| tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | GetHashCodeCore(IEqualityComparer) | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | Item1 | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | Item2 | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | Item[int] | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | Length | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | ToString() | -| tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | ToStringEnd() | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | ValueTuple() | | tuple.cs:7:17:7:22 | (Int32,Int32) | ValueTuple | ValueTuple(int, int) | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | CompareTo((int, int, int, int, int, int, int)) | @@ -25,7 +23,6 @@ members2 | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Equals(object, IEqualityComparer) | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode() | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode(IEqualityComparer) | -| tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCodeCore(IEqualityComparer) | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item1 | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item2 | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item3 | @@ -36,7 +33,6 @@ members2 | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item[int] | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Length | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToString() | -| tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToStringEnd() | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple() | | tuple.cs:12:17:12:37 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple(int, int, int, int, int, int, int) | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | CompareTo((int, int, int, int, int, int, int, int)) | @@ -47,7 +43,6 @@ members2 | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Equals(object, IEqualityComparer) | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode() | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode(IEqualityComparer) | -| tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCodeCore(IEqualityComparer) | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item1 | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item2 | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item3 | @@ -60,7 +55,6 @@ members2 | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Length | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Rest | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToString() | -| tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToStringEnd() | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple() | | tuple.cs:15:17:15:40 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple(int, int, int, int, int, int, int, (int)) | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | CompareTo((int, int, int, int, int, int, int, int, int, int)) | @@ -71,7 +65,6 @@ members2 | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Equals(object, IEqualityComparer) | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode() | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCode(IEqualityComparer) | -| tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | GetHashCodeCore(IEqualityComparer) | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item1 | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item2 | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Item3 | @@ -86,6 +79,5 @@ members2 | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Length | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | Rest | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToString() | -| tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ToStringEnd() | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple() | | tuple.cs:18:17:18:47 | (Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) | ValueTuple | ValueTuple(int, int, int, int, int, int, int, (int, int, int)) | From 65a23499fca664345e0fa204191e49a99e0325ef Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 25 Nov 2024 13:25:16 +0100 Subject: [PATCH 3/5] C#: Bazel build should target .NET9 framework. --- misc/bazel/csharp.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/bazel/csharp.bzl b/misc/bazel/csharp.bzl index be891b142f94..2ba8c59f0767 100644 --- a/misc/bazel/csharp.bzl +++ b/misc/bazel/csharp.bzl @@ -2,7 +2,7 @@ load("@rules_dotnet//dotnet:defs.bzl", "csharp_binary", "csharp_library", "cshar load("@rules_pkg//pkg:mappings.bzl", "strip_prefix") load("//misc/bazel:pkg.bzl", "codeql_pkg_files") -TARGET_FRAMEWORK = "net8.0" +TARGET_FRAMEWORK = "net9.0" def _gen_assembly_info(name): assembly_info_gen = name + "-assembly-info" From d39b6f180186c2b1baf5744dc1d7955f81d3bc63 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 25 Nov 2024 13:56:03 +0100 Subject: [PATCH 4/5] C#: Run unit tests on bazel changes. --- .github/workflows/csharp-qltest.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/csharp-qltest.yml b/.github/workflows/csharp-qltest.yml index cb301d65f9aa..c24b8d3bc007 100644 --- a/.github/workflows/csharp-qltest.yml +++ b/.github/workflows/csharp-qltest.yml @@ -5,8 +5,10 @@ on: paths: - "csharp/**" - "shared/**" + - "misc/bazel/**" - .github/actions/fetch-codeql/action.yml - codeql-workspace.yml + - "MODULE.bazel" branches: - main - "rc/*" @@ -14,9 +16,11 @@ on: paths: - "csharp/**" - "shared/**" + - "misc/bazel/**" - .github/workflows/csharp-qltest.yml - .github/actions/fetch-codeql/action.yml - codeql-workspace.yml + - "MODULE.bazel" branches: - main - "rc/*" From 54324b9d404daa29335473bcae7d22b2e6957f9d Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 26 Nov 2024 09:28:54 +0100 Subject: [PATCH 5/5] C#: Update generics test and expected output from other tests. --- .../assemblies/compilation.expected | 8 +++---- .../format/StringFormatItemParameter.expected | 8 +++++++ .../test/library-tests/generics/Generics.ql | 1 + .../ApplicationModeEndpoints.expected | 24 +++++++++---------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/csharp/ql/test/library-tests/assemblies/compilation.expected b/csharp/ql/test/library-tests/assemblies/compilation.expected index 0119bd5edeee..ee9126f59cee 100644 --- a/csharp/ql/test/library-tests/assemblies/compilation.expected +++ b/csharp/ql/test/library-tests/assemblies/compilation.expected @@ -1,9 +1,9 @@ | Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | no compilation | | Locations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | has compilation | | System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation | -| System.Console, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | +| System.Console, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | | System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation | -| System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e | no compilation | -| System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | -| System.Runtime.Extensions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | +| System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e | no compilation | +| System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | +| System.Runtime.Extensions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation | | mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation | diff --git a/csharp/ql/test/library-tests/frameworks/format/StringFormatItemParameter.expected b/csharp/ql/test/library-tests/frameworks/format/StringFormatItemParameter.expected index 85e2d82f3ab2..978e1340492e 100644 --- a/csharp/ql/test/library-tests/frameworks/format/StringFormatItemParameter.expected +++ b/csharp/ql/test/library-tests/frameworks/format/StringFormatItemParameter.expected @@ -1,3 +1,4 @@ +| Console | Write(string, ReadOnlySpan) | arg | | Console | Write(string, object) | arg0 | | Console | Write(string, object, object) | arg0 | | Console | Write(string, object, object) | arg1 | @@ -5,6 +6,7 @@ | Console | Write(string, object, object, object) | arg1 | | Console | Write(string, object, object, object) | arg2 | | Console | Write(string, params Object[]) | arg | +| Console | WriteLine(string, ReadOnlySpan) | arg | | Console | WriteLine(string, object) | arg0 | | Console | WriteLine(string, object, object) | arg0 | | Console | WriteLine(string, object, object) | arg1 | @@ -15,6 +17,7 @@ | Debug | Assert(bool, string, string, params Object[]) | args | | Debug | Print(string, params Object[]) | args | | Debug | WriteLine(string, params Object[]) | args | +| StringBuilder | AppendFormat(IFormatProvider, string, ReadOnlySpan) | args | | StringBuilder | AppendFormat(IFormatProvider, string, object) | arg0 | | StringBuilder | AppendFormat(IFormatProvider, string, object, object) | arg0 | | StringBuilder | AppendFormat(IFormatProvider, string, object, object) | arg1 | @@ -22,6 +25,7 @@ | StringBuilder | AppendFormat(IFormatProvider, string, object, object, object) | arg1 | | StringBuilder | AppendFormat(IFormatProvider, string, object, object, object) | arg2 | | StringBuilder | AppendFormat(IFormatProvider, string, params Object[]) | args | +| StringBuilder | AppendFormat(string, ReadOnlySpan) | args | | StringBuilder | AppendFormat(string, object) | arg0 | | StringBuilder | AppendFormat(string, object, object) | arg0 | | StringBuilder | AppendFormat(string, object, object) | arg1 | @@ -30,6 +34,7 @@ | StringBuilder | AppendFormat(string, object, object, object) | arg2 | | StringBuilder | AppendFormat(string, params Object[]) | args | | Strings | MyStringFormat(string, params Object[]) | args | +| TextWriter | Write(string, ReadOnlySpan) | arg | | TextWriter | Write(string, object) | arg0 | | TextWriter | Write(string, object, object) | arg0 | | TextWriter | Write(string, object, object) | arg1 | @@ -37,6 +42,7 @@ | TextWriter | Write(string, object, object, object) | arg1 | | TextWriter | Write(string, object, object, object) | arg2 | | TextWriter | Write(string, params Object[]) | arg | +| TextWriter | WriteLine(string, ReadOnlySpan) | arg | | TextWriter | WriteLine(string, object) | arg0 | | TextWriter | WriteLine(string, object, object) | arg0 | | TextWriter | WriteLine(string, object, object) | arg1 | @@ -44,6 +50,7 @@ | TextWriter | WriteLine(string, object, object, object) | arg1 | | TextWriter | WriteLine(string, object, object, object) | arg2 | | TextWriter | WriteLine(string, params Object[]) | arg | +| string | Format(IFormatProvider, string, ReadOnlySpan) | args | | string | Format(IFormatProvider, string, object) | arg0 | | string | Format(IFormatProvider, string, object, object) | arg0 | | string | Format(IFormatProvider, string, object, object) | arg1 | @@ -51,6 +58,7 @@ | string | Format(IFormatProvider, string, object, object, object) | arg1 | | string | Format(IFormatProvider, string, object, object, object) | arg2 | | string | Format(IFormatProvider, string, params Object[]) | args | +| string | Format(string, ReadOnlySpan) | args | | string | Format(string, object) | arg0 | | string | Format(string, object, object) | arg0 | | string | Format(string, object, object) | arg1 | diff --git a/csharp/ql/test/library-tests/generics/Generics.ql b/csharp/ql/test/library-tests/generics/Generics.ql index e75f1fdc9088..ab1f0af982a8 100644 --- a/csharp/ql/test/library-tests/generics/Generics.ql +++ b/csharp/ql/test/library-tests/generics/Generics.ql @@ -223,6 +223,7 @@ query predicate test26(ConstructedGeneric cg, string s) { } query predicate test27(ConstructedType ct, UnboundGenericType ugt, UnboundGenericType sourceDecl) { + ct.fromSource() and ct instanceof NestedType and ugt = ct.getUnboundGeneric() and sourceDecl = ct.getUnboundDeclaration() and diff --git a/csharp/ql/test/utils/modeleditor/ApplicationModeEndpoints.expected b/csharp/ql/test/utils/modeleditor/ApplicationModeEndpoints.expected index 6e0758ca8095..7dcf3b4f8774 100644 --- a/csharp/ql/test/utils/modeleditor/ApplicationModeEndpoints.expected +++ b/csharp/ql/test/utils/modeleditor/ApplicationModeEndpoints.expected @@ -1,12 +1,12 @@ -| NonPublicClass.cs:9:9:9:31 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:9:9:9:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:14:9:14:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:19:9:19:51 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:19:33:19:50 | call to method ReadLine | System | Console | ReadLine | () | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:19:33:19:50 | call to method ReadLine | System | Console | ReadLine | () | true | System.Console | 8.0.0.0 | source | source | -| PublicClass.cs:24:9:24:46 | call to method Write | System | Console | Write | (System.Object) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicClass.cs:30:9:30:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicGenericClass.cs:9:9:9:30 | call to method WriteLine | System | Console | WriteLine | (System.Object) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicGenericClass.cs:14:9:14:30 | call to method WriteLine | System | Console | WriteLine | (System.Object) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicGenericInterface.cs:13:9:13:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | -| PublicInterface.cs:13:9:13:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 8.0.0.0 | neutral | source | +| NonPublicClass.cs:9:9:9:31 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:9:9:9:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:14:9:14:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:19:9:19:51 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:19:33:19:50 | call to method ReadLine | System | Console | ReadLine | () | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:19:33:19:50 | call to method ReadLine | System | Console | ReadLine | () | true | System.Console | 9.0.0.0 | source | source | +| PublicClass.cs:24:9:24:46 | call to method Write | System | Console | Write | (System.Object) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicClass.cs:30:9:30:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicGenericClass.cs:9:9:9:30 | call to method WriteLine | System | Console | WriteLine | (System.Object) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicGenericClass.cs:14:9:14:30 | call to method WriteLine | System | Console | WriteLine | (System.Object) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicGenericInterface.cs:13:9:13:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source | +| PublicInterface.cs:13:9:13:30 | call to method WriteLine | System | Console | WriteLine | (System.String) | true | System.Console | 9.0.0.0 | neutral | source |