Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash the trim analyzer if it finds unrecognized nodes in the input #88836

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using ILLink.Shared.DataFlow;
using Microsoft.CodeAnalysis;

Expand Down Expand Up @@ -29,7 +30,12 @@ public CapturedReferenceValue (IOperation operation)
// These will just be ignored when referenced later.
break;
default:
throw new NotImplementedException (operation.Kind.ToString ());
// Assert on anything else as it means we need to implement support for it
// but do not throw here as it means new Roslyn version could cause the analyzer to crash
// which is not fixable by the user. The analyzer is not going to be 100% correct no matter what we do
// so effectively ignoring constructs it doesn't understand is OK.
Debug.Fail ($"{operation.GetType ()}: {operation.Syntax.GetLocation ().GetLineSpan ()}");
break;
}
Reference = operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ public override TValue VisitSimpleAssignment (ISimpleAssignmentOperation operati
// (don't have specific I*Operation types), such as pointer dereferences.
if (targetOperation.Kind is OperationKind.None)
break;
throw new NotImplementedException ($"{targetOperation.GetType ()}: {targetOperation.Syntax.GetLocation ().GetLineSpan ()}");

// Assert on anything else as it means we need to implement support for it
// but do not throw here as it means new Roslyn version could cause the analyzer to crash
// which is not fixable by the user. The analyzer is not going to be 100% correct no matter what we do
// so effectively ignoring constructs it doesn't understand is OK.
Debug.Fail ($"{targetOperation.GetType ()}: {targetOperation.Syntax.GetLocation ().GetLineSpan ()}");
break;
}
return Visit (operation.Value, state);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using ILLink.RoslynAnalyzer;
using Microsoft.CodeAnalysis;

Expand All @@ -15,18 +15,23 @@ public ParameterProxy (IParameterSymbol parameter)
Index = (ParameterIndex) parameter.Ordinal + (Method.HasImplicitThis () ? 1 : 0);
}

public partial ReferenceKind GetReferenceKind () =>
IsImplicitThis
? Method.Method.ContainingType.IsValueType
? ReferenceKind.Ref
: ReferenceKind.None
: Method.Method.Parameters[MetadataIndex].RefKind switch {
RefKind.Ref => ReferenceKind.Ref,
RefKind.In => ReferenceKind.In,
RefKind.Out => ReferenceKind.Out,
RefKind.None => ReferenceKind.None,
_ => throw new NotImplementedException ($"Unexpected RefKind found on parameter {GetDisplayName ()}")
};
public partial ReferenceKind GetReferenceKind ()
{
if (IsImplicitThis)
return Method.Method.ContainingType.IsValueType
? ReferenceKind.Ref
: ReferenceKind.None;

switch (Method.Method.Parameters[MetadataIndex].RefKind) {
case RefKind.Ref: return ReferenceKind.Ref;
case RefKind.In: return ReferenceKind.In;
case RefKind.Out: return ReferenceKind.Out;
case RefKind.None: return ReferenceKind.None;
default:
Debug.Fail ($"Unexpected RefKind {Method.Method.Parameters[MetadataIndex].RefKind} found on parameter {GetDisplayName ()}");
return ReferenceKind.None;
}
}

/// <summary>
/// Returns the IParameterSymbol representing the parameter. Returns null for the implicit this paramter.
Expand Down
Loading