Skip to content

Commit

Permalink
Add doc to new functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
victornicolet committed Oct 8, 2024
1 parent 564c28f commit 787d47b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
16 changes: 11 additions & 5 deletions analysis/dataflow/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ func (s *AnalyzerState) ReportSummaryNotConstructed(callSite *CallNode) {
}
}

type unsoundFeaturesMap struct {
Recovers map[token.Position]bool
UnsafeUsages map[token.Position]string
// UnsoundFeaturesMap maps positions (in a function) to explanations of the unsound features used.
type UnsoundFeaturesMap struct {
// Recovers records the locations where a recover is used.
Recovers map[token.Position]bool
// UnsafeUsages records the locations where `unsafe` is used, with a short explanation.
UnsafeUsages map[token.Position]string
// ReflectUsages records the locations where 'reflect' is used, with a short explanation.
ReflectUsages map[token.Position]string
}

Expand Down Expand Up @@ -159,7 +163,9 @@ func reportUnsoundFeatures(state *AnalyzerState, f *ssa.Function) {
state.Logger.Warnf(msg)
}
}
func FindUnsoundFeatures(f *ssa.Function) unsoundFeaturesMap {

// FindUnsoundFeatures returns a record of the unsound features used by a function, if any.
func FindUnsoundFeatures(f *ssa.Function) UnsoundFeaturesMap {
unsafeUsages := map[token.Position]string{}
recovers := map[token.Position]bool{}
reflectUsages := map[token.Position]string{}
Expand Down Expand Up @@ -206,5 +212,5 @@ func FindUnsoundFeatures(f *ssa.Function) unsoundFeaturesMap {
}
}
})
return unsoundFeaturesMap{recovers, unsafeUsages, reflectUsages}
return UnsoundFeaturesMap{recovers, unsafeUsages, reflectUsages}
}
29 changes: 13 additions & 16 deletions analysis/dataflow/testdata/unsound-features/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/*
* Copyright (c)
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

Expand Down

0 comments on commit 787d47b

Please sign in to comment.