From 5c5868949303a8e5ba6a7da650da97685de1554e Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 6 Sep 2019 03:35:56 -0700 Subject: [PATCH] [pulse] Add pulse tests for objective-c (the c part of it) Reviewed By: ngorogiannis Differential Revision: D17183375 fbshipit-source-id: 0ecdf2072 --- Makefile | 1 + infer/tests/codetoanalyze/objc/pulse/Makefile | 17 ++++++++++++ .../tests/codetoanalyze/objc/pulse/issues.exp | 2 ++ .../codetoanalyze/objc/pulse/use_after_free.m | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 infer/tests/codetoanalyze/objc/pulse/Makefile create mode 100644 infer/tests/codetoanalyze/objc/pulse/issues.exp create mode 100644 infer/tests/codetoanalyze/objc/pulse/use_after_free.m diff --git a/Makefile b/Makefile index 90a318341..35768be4e 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,7 @@ DIRECT_TESTS += \ objc_liveness \ objc_nullable \ objc_performance \ + objc_pulse \ objc_quandary \ objc_uninit \ objcpp_errors \ diff --git a/infer/tests/codetoanalyze/objc/pulse/Makefile b/infer/tests/codetoanalyze/objc/pulse/Makefile new file mode 100644 index 000000000..ccb5174a1 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/pulse/Makefile @@ -0,0 +1,17 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +TESTS_DIR = ../../.. + +CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS) +INFER_OPTIONS = --pulse-only --debug-exceptions --project-root $(TESTS_DIR) +INFERPRINT_OPTIONS = --issues-tests + +SOURCES = $(wildcard *.m) + +include $(TESTS_DIR)/clang.make +include $(TESTS_DIR)/objc.make + +infer-out/report.json: $(MAKEFILE_LIST) diff --git a/infer/tests/codetoanalyze/objc/pulse/issues.exp b/infer/tests/codetoanalyze/objc/pulse/issues.exp new file mode 100644 index 000000000..02b17e870 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/pulse/issues.exp @@ -0,0 +1,2 @@ +codetoanalyze/objc/pulse/use_after_free.m, PulseTest::use_after_free_simple_in_objc_method_bad:, 2, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,memory was invalidated by call to `free()` here,use-after-lifetime part of the trace starts here,invalid access occurs here] +codetoanalyze/objc/pulse/use_after_free.m, use_after_free_simple_bad, 2, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,memory was invalidated by call to `free()` here,use-after-lifetime part of the trace starts here,invalid access occurs here] diff --git a/infer/tests/codetoanalyze/objc/pulse/use_after_free.m b/infer/tests/codetoanalyze/objc/pulse/use_after_free.m new file mode 100644 index 000000000..2a6028d9b --- /dev/null +++ b/infer/tests/codetoanalyze/objc/pulse/use_after_free.m @@ -0,0 +1,27 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#import + +@interface PulseTest : NSObject + +- (int)use_after_free_simple_in_objc_method_bad:(int*)x; + +@end + +@implementation PulseTest + +- (int)use_after_free_simple_in_objc_method_bad:(int*)x { + free(x); + return *x; +} + +@end + +int use_after_free_simple_bad(int* x) { + free(x); + return *x; +}