Skip to content

Commit 6e41259

Browse files
hajduakosmeta-codesync[bot]
authored andcommitted
[annot] Add Swift test
Summary: Add some tests for reachability in Swift. Reviewed By: dulmarod Differential Revision: D91470952 fbshipit-source-id: abdf20564f0f3dded9b4071dac9ba9f42a802f7a
1 parent edac342 commit 6e41259

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

infer/src/backend/registerCheckers.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ let all_checkers =
198198
(let annot_reach =
199199
interprocedural Payloads.Fields.annot_map AnnotationReachability.checker
200200
in
201-
[(annot_reach, Clang); (annot_reach, Erlang); (annot_reach, Java)] ) }
201+
[(annot_reach, Clang); (annot_reach, Erlang); (annot_reach, Java); (annot_reach, Swift)] )
202+
}
202203
; { checker= ConfigImpactAnalysis
203204
; callbacks=
204205
(let checker =

infer/src/base/Checker.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ let config_unsafe checker =
8888
| AnnotationReachability ->
8989
{ id= "annotation-reachability"
9090
; kind= UserFacing {title= "Annotation Reachability"; markdown_body= ""}
91-
; support= mk_support_func ~clang:Support ~erlang:Support ~java:Support ()
91+
; support=
92+
mk_support_func ~clang:Support ~erlang:Support ~java:Support ~swift:ExperimentalSupport ()
9293
; short_documentation=
9394
"Given pairs of source and sink annotations, e.g. `@A` and `@B`, this checker will warn \
9495
whenever some method annotated with `@A` calls, directly or indirectly, another method \
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"annotation-reachability": true,
3+
"annotation-reachability-custom-pairs": [
4+
{
5+
"sources": ["Source"],
6+
"sinks": ["Sink"],
7+
"sanitizers": ["Sanitizer"]
8+
}
9+
],
10+
"annotation-reachability-custom-models": {
11+
"Source": [".*source.*"],
12+
"Sink": [".*sink.*"],
13+
"Sanitizer": [".*sanitizer.*"]
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
TESTS_DIR = ../../..
7+
SWIFT_OPTIONS = -whole-module-optimization
8+
INFER_OPTIONS = --annotation-reachability-only --debug-exceptions --project-root $(TESTS_DIR)
9+
INFERPRINT_OPTIONS = --issues-tests
10+
11+
SOURCES = $(realpath $(wildcard *.swift) $(wildcard */*.swift))
12+
13+
include $(TESTS_DIR)/infer.make
14+
include $(TESTS_DIR)/swift-base.make
15+
16+
infer-out/report.json: $(SWIFT_DEPS) $(SOURCES) $(MAKEFILE_LIST)
17+
$(QUIET)$(call silent_on_success,Testing infer/swift in $(TEST_REL_DIR),\
18+
$(INFER_BIN) --results-dir $(@D) \
19+
$(INFER_OPTIONS) -- \
20+
$(SWIFTC) $(SWIFT_OPTIONS) $(SOURCES))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codetoanalyze/swift/annotreach/reach.swift, source_Bad, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method source_Bad, marked as source @Source,calls sink,sink defined here, marked as sink @Sink]
2+
codetoanalyze/swift/annotreach/reach.swift, T5Hello7MyClassC.source_Bad, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method T5Hello7MyClassC.source_Bad, marked as source @Source,calls T5Hello7MyClassC.sink,T5Hello7MyClassC.sink defined here, marked as sink @Sink]
3+
codetoanalyze/swift/annotreach/reach.swift, T5Hello12AnotherClassC.source_Bad, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method T5Hello12AnotherClassC.source_Bad, marked as source @Source,calls T5Hello7MyClassC.sink,T5Hello7MyClassC.sink defined here, marked as sink @Sink]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Global functions
2+
func sink() {
3+
}
4+
5+
func sanitizer() {
6+
sink()
7+
}
8+
9+
func source_Bad() {
10+
sink()
11+
}
12+
13+
func source_Ok() {
14+
sanitizer()
15+
}
16+
17+
// Functions in classes
18+
class MyClass {
19+
func sink() {
20+
}
21+
22+
func source_Bad() {
23+
sink()
24+
}
25+
}
26+
27+
// Functions on receiver objects
28+
class AnotherClass {
29+
func not_a_sou_rce_Ok(obj: MyClass) {
30+
obj.sink()
31+
}
32+
33+
func source_Bad(obj: MyClass) {
34+
obj.sink()
35+
}
36+
}

0 commit comments

Comments
 (0)