diff --git a/infer/src/clang/ast_expressions.ml b/infer/src/clang/ast_expressions.ml index b34d57a91..b00d7adb2 100644 --- a/infer/src/clang/ast_expressions.ml +++ b/infer/src/clang/ast_expressions.ml @@ -182,23 +182,6 @@ let make_next_object_exp stmt_info item items = (assignment, loop_cond) -let make_function_call stmt_info fname params = - let expr_info = make_expr_info (builtin_to_qual_type `Void) `XValue `Ordinary in - let name_decl_info = {Clang_ast_t.ni_name= fname; ni_qual_name= [fname]} in - let decl_ref = - make_decl_ref `Function 0 name_decl_info false (Some (builtin_to_qual_type `Void)) - in - let decl_ref_expr_info = make_decl_ref_expr_info decl_ref in - let decl_ref_expr = Clang_ast_t.DeclRefExpr (stmt_info, [], expr_info, decl_ref_expr_info) in - let implicit_cast_expr = - create_implicit_cast_expr stmt_info [decl_ref_expr] - (builtin_to_qual_type `Void) - `FunctionToPointerDecay - in - let stmts = implicit_cast_expr :: params in - Clang_ast_t.CallExpr (stmt_info, stmts, expr_info) - - (* We translate an expression with a conditional*) (* x <=> x?1:0 *) let trans_with_conditional stmt_info expr_info stmt_list = diff --git a/infer/src/clang/ast_expressions.mli b/infer/src/clang/ast_expressions.mli index 4776ff945..b508d85c0 100644 --- a/infer/src/clang/ast_expressions.mli +++ b/infer/src/clang/ast_expressions.mli @@ -26,8 +26,6 @@ val create_implicit_cast_expr : stmt_info -> stmt list -> qual_type -> cast_kind val make_obj_c_message_expr_info_class : string -> Typ.Name.t -> pointer option -> obj_c_message_expr_info -val make_function_call : stmt_info -> string -> stmt list -> stmt - val trans_with_conditional : stmt_info -> expr_info -> stmt list -> stmt (** We translate an expression with a conditional x <=> x?1:0 *) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index ee6c8e247..26a0e3a10 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2770,25 +2770,15 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s instruction trans_state message_stmt - (* @synchronized(anObj) {body} is translated as - - __set_locked_attribue(anObj); - body; - __delete_locked_attribute(anObj); - *) - and objCAtSynchronizedStmt_trans trans_state stmt_list stmt_info = + (* Assumption: stmt_list contains 2 items, the first can be ObjCMessageExpr or ParenExpr *) + (* We ignore this item since we don't deal with the concurrency problem yet *) + (* For the same reason we also ignore the stmt_info that + is related with the ObjCAtSynchronizedStmt construct *) + (* Finally we recursively work on the CompoundStmt, the second item of stmt_list *) + and objCAtSynchronizedStmt_trans trans_state stmt_list = match stmt_list with - | [lockExpr; compound_stmt] -> - let set_lock_stmt = - Ast_expressions.make_function_call stmt_info "__set_locked_attribute" [lockExpr] - in - let set_delete_stmt = - Ast_expressions.make_function_call stmt_info "__delete_locked_attribute" [lockExpr] - in - let sync_compound_stmt = - Clang_ast_t.CompoundStmt (stmt_info, [set_lock_stmt; compound_stmt; set_delete_stmt]) - in - instruction trans_state sync_compound_stmt + | [_; compound_stmt] -> + instruction trans_state compound_stmt | _ -> assert false @@ -3556,8 +3546,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s breakStmt_trans trans_state stmt_info | ContinueStmt (stmt_info, _) -> continueStmt_trans trans_state stmt_info - | ObjCAtSynchronizedStmt (stmt_info, stmt_list) -> - objCAtSynchronizedStmt_trans trans_state stmt_list stmt_info + | ObjCAtSynchronizedStmt (_, stmt_list) -> + objCAtSynchronizedStmt_trans trans_state stmt_list | ObjCIndirectCopyRestoreExpr (_, stmt_list, _) -> let control, returns = instructions trans_state stmt_list in mk_trans_result (last_or_mk_fresh_void_exp_typ returns) control diff --git a/infer/tests/codetoanalyze/objc/frontend/arc/Makefile b/infer/tests/codetoanalyze/objc/frontend/arc/Makefile index 3067633b4..edefe4381 100644 --- a/infer/tests/codetoanalyze/objc/frontend/arc/Makefile +++ b/infer/tests/codetoanalyze/objc/frontend/arc/Makefile @@ -13,7 +13,6 @@ SOURCES = \ ../types/attributes.m \ ../types/void_call.m \ ../vardecl/initlist.m \ - ../synchronizedStmt/sync.m \ ../shared/block/BlockVar.m \ ../shared/block/Blocks_as_parameters.m \ ../shared/memory_leaks_benchmark/ArcExample.m \ diff --git a/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile b/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile index 5eb75fb68..1aadd5566 100644 --- a/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile +++ b/infer/tests/codetoanalyze/objc/frontend/noarc/Makefile @@ -53,7 +53,6 @@ SOURCES = \ ../subclass/MyClass.m \ ../subclass/MySubClass.m \ ../subclass/main.c \ - ../synchronizedStmt/sync.m \ ../types/testloop.m \ ../vardecl/aclass.m \ ../vardecl/aclass_2.m \ diff --git a/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m b/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m deleted file mode 100644 index 28346d63d..000000000 --- a/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - -void foo(int); - -@interface A : NSObject -@end - -@implementation A - -- (void)myMethod:(id)anObj - -{ - @synchronized(anObj) - - { - // Everything between the braces is protected by the @synchronized - // directive. - int x = 0; - x++; - foo(x); - } -} - -@end diff --git a/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m.dot b/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m.dot deleted file mode 100644 index 091e0681d..000000000 --- a/infer/tests/codetoanalyze/objc/frontend/synchronizedStmt/sync.m.dot +++ /dev/null @@ -1,30 +0,0 @@ -/* @generated */ -digraph cfg { -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_1" [label="1: Start A::myMethod:\nFormals: self:A* anObj:objc_object*\nLocals: x:int \n " color=yellow style=filled] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_1" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_7" ; -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_2" [label="2: Exit A::myMethod: \n " color=yellow style=filled] - - -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_3" [label="3: Call _fun___delete_locked_attribute \n n$0=*&anObj:objc_object* [line 19, column 17]\n n$1=_fun___delete_locked_attribute(n$0:objc_object*) [line 19, column 3]\n " shape="box"] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_3" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_2" ; -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_4" [label="4: Call _fun_foo \n n$2=*&x:int [line 26, column 9]\n n$3=_fun_foo(n$2:int) [line 26, column 5]\n " shape="box"] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_4" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_3" ; -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_5" [label="5: UnaryOperator \n n$4=*&x:int [line 25, column 5]\n *&x:int=(n$4 + 1) [line 25, column 5]\n " shape="box"] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_5" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_4" ; -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_6" [label="6: DeclStmt \n VARIABLE_DECLARED(x:int); [line 24, column 5]\n *&x:int=0 [line 24, column 5]\n " shape="box"] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_6" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_5" ; -"myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_7" [label="7: Call _fun___set_locked_attribute \n n$5=*&anObj:objc_object* [line 19, column 17]\n n$6=_fun___set_locked_attribute(n$5:objc_object*) [line 19, column 3]\n " shape="box"] - - - "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_7" -> "myMethod:#A(struct objc_object)#instance.6280971b05d6b617955d8216a04fe405_6" ; -}