From accfc00d82627188317a54eb068340bdc3d9e2e8 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 15 May 2018 08:50:29 -0700 Subject: [PATCH] [objc frontend] Do not crash on internal forward classes Reviewed By: mbouaziz Differential Revision: D8010231 fbshipit-source-id: 2260fa6 --- infer/src/clang/cFrontend_decl.ml | 3 +-- .../ForwardClassInMethod.m | 21 +++++++++++++++++++ .../ForwardClassInMethod.m.dot | 10 +++++++++ .../objc/frontend/noarc/Makefile | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m create mode 100644 infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m.dot diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index 021a78531..a1b0855a9 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -204,7 +204,7 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron | ObjCPropertyImplDecl (_, obj_c_property_impl_decl_info) -> process_property_implementation trans_unit_ctx tenv cfg curr_class obj_c_property_impl_decl_info - | EmptyDecl _ | ObjCIvarDecl _ | ObjCPropertyDecl _ -> + | EmptyDecl _ | ObjCIvarDecl _ | ObjCPropertyDecl _ | ObjCInterfaceDecl _ -> () | AccessSpecDecl _ | BlockDecl _ @@ -224,7 +224,6 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron | ObjCCategoryDecl _ | ObjCCategoryImplDecl _ | ObjCImplementationDecl _ - | ObjCInterfaceDecl _ | ObjCProtocolDecl _ | BuiltinTemplateDecl _ | ClassTemplateDecl _ diff --git a/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m b/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m new file mode 100644 index 000000000..d27e5e8be --- /dev/null +++ b/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import + +@interface A : NSObject + +@end + +@implementation A + +- (void)foo { +} +@class B; + +@end diff --git a/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m.dot b/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m.dot new file mode 100644 index 000000000..8c4be2d07 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/frontend/internal_forward_class/ForwardClassInMethod.m.dot @@ -0,0 +1,10 @@ +/* @generated */ +digraph cfg { +"foo#A#instance.a1bcc3cb6c1f00fc285817fb8454eaed_1" [label="1: Start A_foo\nFormals: self:A*\nLocals: \n DECLARE_LOCALS(&return); [line 17, column 1]\n " color=yellow style=filled] + + + "foo#A#instance.a1bcc3cb6c1f00fc285817fb8454eaed_1" -> "foo#A#instance.a1bcc3cb6c1f00fc285817fb8454eaed_2" ; +"foo#A#instance.a1bcc3cb6c1f00fc285817fb8454eaed_2" [label="2: Exit A_foo \n " color=yellow style=filled] + + +} diff --git a/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile b/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile index a64080bf3..77aefecf9 100644 --- a/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile +++ b/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile @@ -27,6 +27,7 @@ SOURCES = \ ../conditional_operation/ConditionalOperation.m \ ../exceptions/ExceptionExample.m \ ../fast_enumeration/Fast_enumeration.m \ + ../internal_forward_class/ForwardClassInMethod.m \ ../property/PropertyCustomAccessor.m \ ../property/PropertyImplSetter.m \ ../property/Property_getter.m \