public static ValueContentAnalysisResult?TryGetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, PointsToAnalysisKind defaultPointsToAnalysisKind, CancellationToken cancellationToken, out CopyAnalysisResult?copyAnalysisResultOpt, out PointsToAnalysisResult?pointsToAnalysisResultOpt, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.None, bool pessimisticAnalysis = true, bool performCopyAnalysisIfNotUserConfigured = false, InterproceduralAnalysisPredicate?interproceduralAnalysisPredicateOpt = null) { Debug.Assert(!owningSymbol.IsConfiguredToSkipAnalysis(analyzerOptions, rule, wellKnownTypeProvider.Compilation, cancellationToken)); var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, owningSymbol, wellKnownTypeProvider.Compilation, interproceduralAnalysisKind, cancellationToken); return(TryGetOrComputeResult(cfg, owningSymbol, analyzerOptions, wellKnownTypeProvider, pointsToAnalysisKind: analyzerOptions.GetPointsToAnalysisKindOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultPointsToAnalysisKind, cancellationToken), interproceduralAnalysisConfig, out copyAnalysisResultOpt, out pointsToAnalysisResultOpt, pessimisticAnalysis, performCopyAnalysis: analyzerOptions.GetCopyAnalysisOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: performCopyAnalysisIfNotUserConfigured, cancellationToken), interproceduralAnalysisPredicateOpt: interproceduralAnalysisPredicateOpt)); }
/// <summary> /// Performs global flow state analysis and returns the analysis result. /// </summary> /// <param name="cfg">Control flow graph to analyze.</param> /// <param name="owningSymbol">Owning symbol for the analyzed <paramref name="cfg"/>.</param> /// <param name="createOperationVisitor">Delegate to create a <see cref="GlobalFlowStateDataFlowOperationVisitor"/> that performs the core analysis.</param> /// <param name="wellKnownTypeProvider">Well-known type provider for the compilation.</param> /// <param name="analyzerOptions">Analyzer options for analysis</param> /// <param name="rule"><see cref="DiagnosticDescriptor"/> for fetching any rule specific analyzer option values from <paramref name="analyzerOptions"/>.</param> /// <param name="performValueContentAnalysis">Flag to indicate if <see cref="ValueContentAnalysis.ValueContentAnalysis"/> should be performed.</param> /// <param name="pessimisticAnalysis"> /// This boolean field determines if we should perform an optimistic OR a pessimistic analysis. /// For example, invoking a lambda method for which we do not know the target method being invoked can change/invalidate the current global flow state. /// An optimistic points to analysis assumes that the global flow state doesn't change for such scenarios. /// A pessimistic points to analysis resets the global flow state to an unknown state for such scenarios. /// </param> /// <param name="cancellationToken">Token to cancel analysis.</param> /// <param name="valueContentAnalysisResult">Optional value content analysis result, if <paramref name="performValueContentAnalysis"/> is true</param> /// <param name="interproceduralAnalysisKind"><see cref="InterproceduralAnalysisKind"/> for the analysis.</param> /// <param name="interproceduralAnalysisPredicate">Optional predicate for interprocedural analysis.</param> /// <param name="additionalSupportedValueTypes">Additional value types for which the caller wants to track stored values during value content analysis.</param> /// <param name="getValueContentValueForAdditionalSupportedValueTypeOperation"> /// Optional delegate to compute values for <paramref name="additionalSupportedValueTypes"/>. /// Must be non-null if <paramref name="additionalSupportedValueTypes"/> is non-empty. /// </param> /// <returns>Global flow state analysis result, or null if analysis did not succeed.</returns> public static GlobalFlowStateAnalysisResult?TryGetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, Func <GlobalFlowStateAnalysisContext, GlobalFlowStateDataFlowOperationVisitor> createOperationVisitor, WellKnownTypeProvider wellKnownTypeProvider, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, bool performValueContentAnalysis, bool pessimisticAnalysis, CancellationToken cancellationToken, out ValueContentAnalysisResult?valueContentAnalysisResult, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.None, InterproceduralAnalysisPredicate?interproceduralAnalysisPredicate = null, ImmutableArray <INamedTypeSymbol> additionalSupportedValueTypes = default, Func <IOperation, ValueContentAbstractValue>?getValueContentValueForAdditionalSupportedValueTypeOperation = null) { if (cfg == null) { throw new ArgumentNullException(nameof(cfg)); } var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, cfg, wellKnownTypeProvider.Compilation, interproceduralAnalysisKind, cancellationToken); var pointsToAnalysisKind = analyzerOptions.GetPointsToAnalysisKindOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: PointsToAnalysisKind.PartialWithoutTrackingFieldsAndProperties, cancellationToken); return(TryGetOrComputeResult(cfg, owningSymbol, createOperationVisitor, wellKnownTypeProvider, analyzerOptions, interproceduralAnalysisConfig, interproceduralAnalysisPredicate, pointsToAnalysisKind, pessimisticAnalysis, performValueContentAnalysis, out valueContentAnalysisResult, additionalSupportedValueTypes, getValueContentValueForAdditionalSupportedValueTypeOperation)); }
public static ValueContentAnalysisResult?TryGetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, PointsToAnalysisKind defaultPointsToAnalysisKind, out CopyAnalysisResult?copyAnalysisResult, out PointsToAnalysisResult?pointsToAnalysisResult, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.None, bool pessimisticAnalysis = true, bool performCopyAnalysisIfNotUserConfigured = false, InterproceduralAnalysisPredicate?interproceduralAnalysisPredicate = null, ImmutableArray <INamedTypeSymbol> additionalSupportedValueTypes = default, Func <IOperation, ValueContentAbstractValue>?getValueContentValueForAdditionalSupportedValueTypeOperation = null) { if (cfg == null) { throw new ArgumentNullException(nameof(cfg)); } Debug.Assert(!analyzerOptions.IsConfiguredToSkipAnalysis(rule, owningSymbol, wellKnownTypeProvider.Compilation)); var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, cfg, wellKnownTypeProvider.Compilation, interproceduralAnalysisKind); return(TryGetOrComputeResult(cfg, owningSymbol, analyzerOptions, wellKnownTypeProvider, pointsToAnalysisKind: analyzerOptions.GetPointsToAnalysisKindOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultPointsToAnalysisKind), interproceduralAnalysisConfig, out copyAnalysisResult, out pointsToAnalysisResult, pessimisticAnalysis, performCopyAnalysis: analyzerOptions.GetCopyAnalysisOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: performCopyAnalysisIfNotUserConfigured), interproceduralAnalysisPredicate, additionalSupportedValueTypes, getValueContentValueForAdditionalSupportedValueTypeOperation)); }
public static ImmutableDictionary <IParameterSymbol, SyntaxNode> GetOrComputeHazardousParameterUsages( IBlockOperation topmostBlock, Compilation compilation, ISymbol owningSymbol, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, CancellationToken cancellationToken, PointsToAnalysisKind defaultPointsToAnalysisKind = PointsToAnalysisKind.PartialWithoutTrackingFieldsAndProperties, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.ContextSensitive, uint defaultMaxInterproceduralMethodCallChain = 1, // By default, we only want to track method calls one level down. bool pessimisticAnalysis = false) { Debug.Assert(!analyzerOptions.IsConfiguredToSkipAnalysis(rule, owningSymbol, compilation, cancellationToken)); var cfg = topmostBlock.GetEnclosingControlFlowGraph(); if (cfg == null) { return(ImmutableDictionary <IParameterSymbol, SyntaxNode> .Empty); } var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, cfg, compilation, interproceduralAnalysisKind, cancellationToken, defaultMaxInterproceduralMethodCallChain); var performCopyAnalysis = analyzerOptions.GetCopyAnalysisOption(rule, topmostBlock.Syntax.SyntaxTree, compilation, defaultValue: false, cancellationToken); var nullCheckValidationMethods = analyzerOptions.GetNullCheckValidationMethodsOption(rule, topmostBlock.Syntax.SyntaxTree, compilation, cancellationToken); var pointsToAnalysisKind = analyzerOptions.GetPointsToAnalysisKindOption(rule, topmostBlock.Syntax.SyntaxTree, compilation, defaultPointsToAnalysisKind, cancellationToken); return(GetOrComputeHazardousParameterUsages(cfg, compilation, owningSymbol, analyzerOptions, nullCheckValidationMethods, pointsToAnalysisKind, interproceduralAnalysisConfig, performCopyAnalysis, pessimisticAnalysis)); }
public static PointsToAnalysisKind GetPointsToAnalysisKindOption( this AnalyzerOptions options, DiagnosticDescriptor rule, ISymbol symbol, Compilation compilation, PointsToAnalysisKind defaultValue) => TryGetSyntaxTreeForOption(symbol, out var tree) ? options.GetPointsToAnalysisKindOption(rule, tree, compilation, defaultValue) : defaultValue;
public static DisposeAnalysisResult?TryGetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, WellKnownTypeProvider wellKnownTypeProvider, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, ImmutableHashSet <INamedTypeSymbol> disposeOwnershipTransferLikelyTypes, PointsToAnalysisKind defaultPointsToAnalysisKind, bool trackInstanceFields, bool exceptionPathsAnalysis, CancellationToken cancellationToken, out PointsToAnalysisResult?pointsToAnalysisResult, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.ContextSensitive, bool performCopyAnalysisIfNotUserConfigured = false, InterproceduralAnalysisPredicate?interproceduralAnalysisPredicate = null, bool defaultDisposeOwnershipTransferAtConstructor = false, bool defaultDisposeOwnershipTransferAtMethodCall = false) { if (cfg == null) { throw new ArgumentNullException(nameof(cfg)); } Debug.Assert(!analyzerOptions.IsConfiguredToSkipAnalysis(rule, owningSymbol, wellKnownTypeProvider.Compilation, cancellationToken)); var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, cfg, wellKnownTypeProvider.Compilation, interproceduralAnalysisKind, cancellationToken); var disposeOwnershipTransferAtConstructor = analyzerOptions.GetDisposeOwnershipTransferAtConstructorOption( rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: defaultDisposeOwnershipTransferAtConstructor, cancellationToken); var disposeOwnershipTransferAtMethodCall = analyzerOptions.GetDisposeOwnershipTransferAtMethodCall( rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: defaultDisposeOwnershipTransferAtMethodCall, cancellationToken); return(TryGetOrComputeResult(cfg, owningSymbol, analyzerOptions, wellKnownTypeProvider, interproceduralAnalysisConfig, interproceduralAnalysisPredicate, disposeOwnershipTransferLikelyTypes, disposeOwnershipTransferAtConstructor, disposeOwnershipTransferAtMethodCall, trackInstanceFields, exceptionPathsAnalysis, pointsToAnalysisKind: analyzerOptions.GetPointsToAnalysisKindOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultPointsToAnalysisKind, cancellationToken), performCopyAnalysis: analyzerOptions.GetCopyAnalysisOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: performCopyAnalysisIfNotUserConfigured, cancellationToken), isConfiguredToSkipAnalysis: (ISymbol symbol) => analyzerOptions.IsConfiguredToSkipAnalysis(rule, symbol, owningSymbol, wellKnownTypeProvider.Compilation, cancellationToken), out pointsToAnalysisResult)); }
public static GlobalFlowStateAnalysisResult?TryGetOrComputeResult( ControlFlowGraph cfg, ISymbol owningSymbol, Func <GlobalFlowStateAnalysisContext, GlobalFlowStateDataFlowOperationVisitor> createOperationVisitor, WellKnownTypeProvider wellKnownTypeProvider, AnalyzerOptions analyzerOptions, DiagnosticDescriptor rule, bool performValueContentAnalysis, CancellationToken cancellationToken, out ValueContentAnalysisResult?valueContentAnalysisResult, InterproceduralAnalysisKind interproceduralAnalysisKind = InterproceduralAnalysisKind.None, bool pessimisticAnalysis = true, InterproceduralAnalysisPredicate?interproceduralAnalysisPredicate = null) { var interproceduralAnalysisConfig = InterproceduralAnalysisConfiguration.Create( analyzerOptions, rule, owningSymbol, wellKnownTypeProvider.Compilation, interproceduralAnalysisKind, cancellationToken); var pointsToAnalysisKind = analyzerOptions.GetPointsToAnalysisKindOption(rule, owningSymbol, wellKnownTypeProvider.Compilation, defaultValue: PointsToAnalysisKind.PartialWithoutTrackingFieldsAndProperties, cancellationToken); return(TryGetOrComputeResult(cfg, owningSymbol, createOperationVisitor, wellKnownTypeProvider, analyzerOptions, interproceduralAnalysisConfig, interproceduralAnalysisPredicate, pointsToAnalysisKind, pessimisticAnalysis, performValueContentAnalysis, out valueContentAnalysisResult)); }