未验证 提交 655ada40 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #36097 from mavasani/NuGetPackageUpdate

Upgrade Microsoft.CodeAnalysis.FlowAnalysis.Utilities PackageReference to latest version
......@@ -47,7 +47,7 @@
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.17</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion>$(MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion>
<MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>$(CodeStyleAnalyzerVersion)</MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>
<MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion>2.9.3-beta1.19271.2+23ca1e2d</MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion>
<MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion>2.9.3-beta1.19301.2+4c8365b9</MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion>
<MicrosoftCodeQualityAnalyzersVersion>$(RoslynDiagnosticsNugetPackageVersion)</MicrosoftCodeQualityAnalyzersVersion>
<SystemCompositionVersion>1.0.31</SystemCompositionVersion>
<MicrosoftCSharpVersion>4.3.0</MicrosoftCSharpVersion>
......
......@@ -1943,8 +1943,8 @@ End Module")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.DisposeAnalysis)>
Public Async Function DisposableCreationNotAssignedToAVariable_Diagnostic() As Task
Await TestDiagnosticsAsync(
Public Async Function DisposableCreationNotAssignedToAVariable_BailOut_NoDiagnostic() As Task
Await TestDiagnosticMissingAsync(
"Imports System
Class A
......@@ -1967,8 +1967,7 @@ Class Test
New A(2).M() ' Error
Dim x = New A(3).X
End Sub|]
End Class",
Diagnostic(IDEDiagnosticIds.DisposeObjectsBeforeLosingScopeDiagnosticId, "New A(3)").WithLocation(21, 17))
End Class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.DisposeAnalysis)>
......
......@@ -55,6 +55,7 @@ private sealed class SymbolAnalyzer
private readonly ImmutableHashSet<IFieldSymbol> _disposableFields;
private readonly ConcurrentDictionary<IFieldSymbol, /*disposed*/bool> _fieldDisposeValueMap;
private readonly DisposeAnalysisHelper _disposeAnalysisHelper;
private bool _hasErrors;
public SymbolAnalyzer(ImmutableHashSet<IFieldSymbol> disposableFields, DisposeAnalysisHelper disposeAnalysisHelper)
{
......@@ -110,6 +111,11 @@ private void AddOrUpdateFieldDisposedValue(IFieldSymbol field, bool disposed)
private void OnSymbolEnd(SymbolAnalysisContext symbolEndContext)
{
if (_hasErrors)
{
return;
}
foreach (var kvp in _fieldDisposeValueMap)
{
IFieldSymbol field = kvp.Key;
......@@ -126,6 +132,13 @@ private void OnSymbolEnd(SymbolAnalysisContext symbolEndContext)
[MethodImpl(MethodImplOptions.NoInlining)]
private void OnOperationBlockStart(OperationBlockStartAnalysisContext operationBlockStartContext)
{
if (_hasErrors)
{
return;
}
operationBlockStartContext.RegisterOperationAction(_ => _hasErrors = true, OperationKind.Invalid);
switch (operationBlockStartContext.OwningSymbol)
{
case IFieldSymbol _:
......@@ -182,7 +195,8 @@ void AnalyzeFieldReference(OperationAnalysisContext operationContext)
// Check if this is a Disposable field that is not currently being tracked.
if (_fieldDisposeValueMap.ContainsKey(field) ||
!_disposableFields.Contains(field))
!_disposableFields.Contains(field) ||
_hasErrors)
{
return;
}
......@@ -209,6 +223,11 @@ void AnalyzeFieldReference(OperationAnalysisContext operationContext)
{
Interlocked.CompareExchange(ref lazyPointsToAnalysisResult, pointsToAnalysisResult, null);
}
else
{
_hasErrors = true;
return;
}
}
PointsToAbstractValue assignedPointsToValue = lazyPointsToAnalysisResult[simpleAssignmentOperation.Value.Kind, simpleAssignmentOperation.Value.Syntax];
......@@ -225,6 +244,11 @@ void AnalyzeFieldReference(OperationAnalysisContext operationContext)
void AnalyzeDisposeMethod()
{
if (_hasErrors)
{
return;
}
// Perform dataflow analysis to compute dispose value of disposable fields at the end of dispose method.
if (_disposeAnalysisHelper.TryGetOrComputeResult(operationBlockStartContext, containingMethod,
s_disposableFieldsShouldBeDisposedRule, trackInstanceFields: true,
......@@ -268,6 +292,10 @@ void AnalyzeDisposeMethod()
}
}
}
else
{
_hasErrors = true;
}
}
}
}
......
......@@ -109,12 +109,15 @@ private void EnsureDisposableFieldsMap()
if (cfg != null)
{
var wellKnownTypeProvider = WellKnownTypeProvider.GetOrCreate(context.Compilation);
disposeAnalysisResult = FlowAnalysis.DataFlow.DisposeAnalysis.DisposeAnalysis.GetOrComputeResult(cfg, containingMethod, wellKnownTypeProvider,
disposeAnalysisResult = FlowAnalysis.DataFlow.DisposeAnalysis.DisposeAnalysis.TryGetOrComputeResult(cfg, containingMethod, wellKnownTypeProvider,
context.Options, rule, _disposeOwnershipTransferLikelyTypes, trackInstanceFields,
exceptionPathsAnalysis: false, context.CancellationToken, out pointsToAnalysisResult,
interproceduralAnalysisPredicateOpt: interproceduralAnalysisPredicateOpt,
defaultDisposeOwnershipTransferAtConstructor: true);
return true;
if (disposeAnalysisResult != null)
{
return true;
}
}
}
......@@ -140,12 +143,15 @@ private void EnsureDisposableFieldsMap()
if (cfg != null)
{
var wellKnownTypeProvider = WellKnownTypeProvider.GetOrCreate(context.Compilation);
disposeAnalysisResult = FlowAnalysis.DataFlow.DisposeAnalysis.DisposeAnalysis.GetOrComputeResult(cfg, containingMethod, wellKnownTypeProvider,
disposeAnalysisResult = FlowAnalysis.DataFlow.DisposeAnalysis.DisposeAnalysis.TryGetOrComputeResult(cfg, containingMethod, wellKnownTypeProvider,
context.Options, rule, _disposeOwnershipTransferLikelyTypes, trackInstanceFields,
exceptionPathsAnalysis: false, context.CancellationToken, out pointsToAnalysisResult,
interproceduralAnalysisPredicateOpt: interproceduralAnalysisPredicateOpt,
defaultDisposeOwnershipTransferAtConstructor: true);
return true;
if (disposeAnalysisResult != null)
{
return true;
}
}
}
......
......@@ -125,7 +125,7 @@
<ItemGroup>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
<PackageReference Include="Microsoft.DiaSymReader" Version="$(MicrosoftDiaSymReaderVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.FlowAnalysis.Utilities" Version="$(MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.FlowAnalysis.Utilities" Version="$(MicrosoftCodeAnalysisFlowAnalysisUtilitiesVersion)" />
</ItemGroup>
<Import Project="..\..\..\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems" Label="Shared" />
<Import Project="..\..\..\Dependencies\CodeAnalysis.Debugging\Microsoft.CodeAnalysis.Debugging.projitems" Label="Shared" />
......
......@@ -48,6 +48,7 @@
-->
<ItemGroup>
<ExpectedDependency Include="Humanizer.Core"/>
<ExpectedDependency Include="Microsoft.CodeAnalysis.FlowAnalysis.Utilities"/>
<ExpectedDependency Include="ICSharpCode.Decompiler"/>
<ExpectedDependency Include="Microsoft.DiaSymReader"/>
<ExpectedDependency Include="Microsoft.CodeAnalysis.Elfie"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册