diff --git a/Makefile b/Makefile index 35768be4e..ca5db0e9d 100644 --- a/Makefile +++ b/Makefile @@ -114,6 +114,7 @@ DIRECT_TESTS += \ objcpp_linters-for-test-only \ objcpp_liveness \ objcpp_nullable \ + objcpp_pulse \ objcpp_racerd \ objcpp_retain-cycles \ diff --git a/infer/tests/codetoanalyze/objcpp/pulse/Makefile b/infer/tests/codetoanalyze/objcpp/pulse/Makefile new file mode 100644 index 000000000..bb52b9734 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/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 $(OBJCPP_CLANG_OPTIONS) +INFER_OPTIONS = --pulse-only --debug-exceptions --project-root $(TESTS_DIR) +INFERPRINT_OPTIONS = --issues-tests + +SOURCES = $(wildcard *.mm) + +include $(TESTS_DIR)/clang.make +include $(TESTS_DIR)/objc.make + +infer-out/report.json: $(MAKEFILE_LIST) diff --git a/infer/tests/codetoanalyze/objcpp/pulse/issues.exp b/infer/tests/codetoanalyze/objcpp/pulse/issues.exp new file mode 100644 index 000000000..c796d4aae --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/pulse/issues.exp @@ -0,0 +1,2 @@ +codetoanalyze/objcpp/pulse/use_after_delete.mm, PulseTest::deref_deleted_in_objc_method_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `Simple::Simple()` here,invalid access occurs here] +codetoanalyze/objcpp/pulse/use_after_delete.mm, deref_deleted_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `Simple::Simple()` here,invalid access occurs here] diff --git a/infer/tests/codetoanalyze/objcpp/pulse/use_after_delete.mm b/infer/tests/codetoanalyze/objcpp/pulse/use_after_delete.mm new file mode 100644 index 000000000..b97c0b517 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/pulse/use_after_delete.mm @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#include +#include +#include + +#import + +struct Simple { + int f; +}; + +@interface PulseTest : NSObject + +- (int)deref_deleted_in_objc_method_bad; + +@end + +@implementation PulseTest + +- (int)deref_deleted_in_objc_method_bad { + auto* s = new Simple{1}; + delete s; + Simple tmp = *s; +} + +@end + +void deref_deleted_bad() { + auto* s = new Simple{1}; + delete s; + Simple tmp = *s; +}