Skip to content

Commit 10448b6

Browse files
committed
Handle default expression value properly in Value content analysis
Fixes #6164
1 parent cec0794 commit 10448b6

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/Utilities/Compiler/Extensions/ITypeSymbolExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ public static bool IsAttribute(this ITypeSymbol symbol)
294294
public static bool HasValueCopySemantics(this ITypeSymbol typeSymbol)
295295
=> typeSymbol.IsValueType || typeSymbol.SpecialType == SpecialType.System_String;
296296

297+
public static bool HasReferenceTypeSemantics([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
298+
=> typeSymbol.IsReferenceTypeOrNullableValueType() ||
299+
typeSymbol?.IsRefLikeType == true ||
300+
typeSymbol is ITypeParameterSymbol typeParameter && !typeParameter.IsValueType;
301+
297302
public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
298303
=> typeSymbol != null && typeSymbol.IsValueType && typeSymbol.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T;
299304

src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/PointsToAnalysis/PointsToAnalysis.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ private PointsToAnalysis(PointsToAnalysisDomain analysisDomain, PointsToDataFlow
9090
}
9191

9292
internal static bool ShouldBeTracked([NotNullWhen(returnValue: true)] ITypeSymbol? typeSymbol, Func<ITypeSymbol?, bool> isDisposable)
93-
=> typeSymbol.IsReferenceTypeOrNullableValueType() ||
94-
typeSymbol?.IsRefLikeType == true ||
95-
typeSymbol is ITypeParameterSymbol typeParameter && !typeParameter.IsValueType ||
93+
=> typeSymbol.HasReferenceTypeSemantics() ||
9694
isDisposable(typeSymbol);
9795

9896
internal static bool ShouldBeTracked(AnalysisEntity analysisEntity, PointsToAnalysisKind pointsToAnalysisKind, Func<ITypeSymbol?, bool> isDisposable)

src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAnalysis.ValueContentDataFlowOperationVisitor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Collections.Immutable;
6+
using Analyzer.Utilities.Extensions;
67
using Microsoft.CodeAnalysis.FlowAnalysis.DataFlow.CopyAnalysis;
78
using Microsoft.CodeAnalysis.Operations;
89

@@ -62,7 +63,7 @@ protected override ValueContentAbstractValue GetAbstractValue(AnalysisEntity ana
6263
=> CurrentAnalysisData.TryGetValue(analysisEntity, out var value) ? value : ValueDomain.UnknownOrMayBeValue;
6364

6465
protected override ValueContentAbstractValue GetAbstractDefaultValue(ITypeSymbol? type)
65-
=> type != null ?
66+
=> type != null && !type.HasReferenceTypeSemantics() ?
6667
ValueContentAbstractValue.DoesNotContainLiteralOrNonLiteralState :
6768
ValueContentAbstractValue.ContainsNullLiteralState;
6869

0 commit comments

Comments
 (0)