From 64bb3b62b34d5b61278299d1a89f6e384b1f88d4 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Fri, 8 Apr 2016 07:50:46 -0700 Subject: [PATCH] Use variable stmt location info in init_res_trans Summary:public Instead of using location of init_stmt, use location of variable when translating initialization. Most of the time it change anything with some exceptions: // example1 - C/C++/objC int x = // now: assignment happens in this line 3; // past: assignment happens in this line // example2: valid in C++11 only struct X { int x = 0; // now: one assignment here int y = 2; // now: one assigmnent here X() = default; // before: 2 assignments in this line }; Reviewed By: dulmarod Differential Revision: D3155870 fb-gh-sync-id: f38c78c fbshipit-source-id: f38c78c --- infer/src/clang/cTrans.ml | 10 +++++----- .../frontend/constructors/default_field_init.cpp.dot | 6 +++--- .../memory_leaks_benchmark/MemoryLeakExample.dot | 6 +++--- .../codetoanalyze/objc/frontend/block/block-it.dot | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 56fa8ebce..874d5adf2 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -1675,10 +1675,9 @@ struct (* Nothing to do if no init expression *) { empty_res_trans with root_nodes = trans_state.succ_nodes } | Some ie -> (*For init expr, translate how to compute it and assign to the var*) - let stmt_info, _ = Clang_ast_proj.get_stmt_tuple ie in let var_exp, _ = var_exp_typ in let context = trans_state.context in - let sil_loc = CLocation.get_sil_location stmt_info context in + let sil_loc = CLocation.get_sil_location var_stmt_info context in let trans_state_pri = PriorityNode.try_claim_priority_node trans_state var_stmt_info in (* if ie is a block the translation need to be done with the block special cases by exec_with_block_priority *) @@ -2537,12 +2536,13 @@ struct and cxx_constructor_init_trans ctor_init trans_state = (*let tenv = trans_state.context.CContext.tenv in*) let class_name = CContext.get_curr_class_name trans_state.context.CContext.curr_class in - let sil_loc = - CLocation.get_sil_location_from_range ctor_init.Clang_ast_t.xci_source_range true in + let source_range = ctor_init.Clang_ast_t.xci_source_range in + let sil_loc = CLocation.get_sil_location_from_range source_range true in (* its pointer will be used in PriorityNode *) let this_stmt_info = Ast_expressions.dummy_stmt_info () in (* this will be used to avoid creating node in init_expr_trans *) - let child_stmt_info = Ast_expressions.dummy_stmt_info () in + let child_stmt_info = + { (Ast_expressions.dummy_stmt_info ()) with Clang_ast_t.si_source_range = source_range } in let trans_state' = PriorityNode.try_claim_priority_node trans_state this_stmt_info in let class_type_ptr = Ast_expressions.create_pointer_type (Ast_expressions.create_class_type (class_name, `CPP)) in diff --git a/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot index d57d6ab20..00c60a804 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot @@ -37,7 +37,7 @@ digraph iCFG { 9 -> 8 ; -8 [label="8: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =0 [line 16]\n REMOVE_TEMPS(n$0); [line 16]\n NULLIFY(&this,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"] +8 [label="8: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =0 [line 13]\n REMOVE_TEMPS(n$0); [line 13]\n NULLIFY(&this,false); [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"] 8 -> 7 ; @@ -48,7 +48,7 @@ digraph iCFG { 6 -> 10 ; -5 [label="5: Constructor Init \n n$2=*&this:class X * [line 11]\n *n$2.a:int =-1 [line 15]\n REMOVE_TEMPS(n$2); [line 15]\n " shape="box"] +5 [label="5: Constructor Init \n n$2=*&this:class X * [line 11]\n *n$2.a:int =-1 [line 11]\n REMOVE_TEMPS(n$2); [line 11]\n " shape="box"] 5 -> 4 ; @@ -56,7 +56,7 @@ digraph iCFG { 4 -> 3 ; -3 [label="3: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =0 [line 15]\n REMOVE_TEMPS(n$0); [line 15]\n NULLIFY(&this,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"] +3 [label="3: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =0 [line 13]\n REMOVE_TEMPS(n$0); [line 13]\n NULLIFY(&this,false); [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"] 3 -> 2 ; diff --git a/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot index d208c5040..bbc3766cf 100644 --- a/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot +++ b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot @@ -210,7 +210,7 @@ digraph iCFG { 20 -> 22 ; -19 [label="19: DeclStmt \n n$16=_fun_CFAttributedStringCreateMutable(0:struct __CFAllocator *,0:long ) [line 40]\n *&maString:struct __CFAttributedString *=n$16 [line 40]\n REMOVE_TEMPS(n$16); [line 40]\n " shape="box"] +19 [label="19: DeclStmt \n n$16=_fun_CFAttributedStringCreateMutable(0:struct __CFAllocator *,0:long ) [line 40]\n *&maString:struct __CFAttributedString *=n$16 [line 39]\n REMOVE_TEMPS(n$16); [line 39]\n " shape="box"] 19 -> 18 ; @@ -236,7 +236,7 @@ digraph iCFG { 13 -> 15 ; -12 [label="12: DeclStmt \n n$10=*&self:class MemoryLeakExample * [line 30]\n n$11=_fun_MemoryLeakExample_backgroundCoveringView(n$10:class MemoryLeakExample *) [line 30]\n n$12=_fun_UIView_bounds(n$11:class UIView *) [line 30]\n n$13=_fun_CGPathCreateWithRect(n$12:struct CGRect ,0:struct CGAffineTransform *) [line 30]\n *&shadowPath:struct CGPath *=n$13 [line 30]\n REMOVE_TEMPS(n$10,n$11,n$12,n$13); [line 30]\n " shape="box"] +12 [label="12: DeclStmt \n n$10=*&self:class MemoryLeakExample * [line 30]\n n$11=_fun_MemoryLeakExample_backgroundCoveringView(n$10:class MemoryLeakExample *) [line 30]\n n$12=_fun_UIView_bounds(n$11:class UIView *) [line 30]\n n$13=_fun_CGPathCreateWithRect(n$12:struct CGRect ,0:struct CGAffineTransform *) [line 30]\n *&shadowPath:struct CGPath *=n$13 [line 29]\n REMOVE_TEMPS(n$10,n$11,n$12,n$13); [line 29]\n " shape="box"] 12 -> 11 ; @@ -255,7 +255,7 @@ digraph iCFG { 8 -> 7 ; -7 [label="7: DeclStmt \n n$2=*&attachmentContainerView:class UIView * [line 22]\n n$3=_fun_UIView_bounds(n$2:class UIView *) [line 22]\n n$4=_fun_CGPathCreateWithRect(n$3:struct CGRect ,0:struct CGAffineTransform *) [line 22]\n *&shadowPath:struct CGPath *=n$4 [line 22]\n REMOVE_TEMPS(n$2,n$3,n$4); [line 22]\n " shape="box"] +7 [label="7: DeclStmt \n n$2=*&attachmentContainerView:class UIView * [line 22]\n n$3=_fun_UIView_bounds(n$2:class UIView *) [line 22]\n n$4=_fun_CGPathCreateWithRect(n$3:struct CGRect ,0:struct CGAffineTransform *) [line 22]\n *&shadowPath:struct CGPath *=n$4 [line 21]\n REMOVE_TEMPS(n$2,n$3,n$4); [line 21]\n " shape="box"] 7 -> 6 ; diff --git a/infer/tests/codetoanalyze/objc/frontend/block/block-it.dot b/infer/tests/codetoanalyze/objc/frontend/block/block-it.dot index ac6a46b41..3cf03b893 100644 --- a/infer/tests/codetoanalyze/objc/frontend/block/block-it.dot +++ b/infer/tests/codetoanalyze/objc/frontend/block/block-it.dot @@ -7,7 +7,7 @@ digraph iCFG { 53 -> 52 ; -52 [label="52: DeclStmt \n DECLARE_LOCALS(&__objc_anonymous_block_MyBlock_array_trans______2); [line 40]\n n$42=_fun___objc_alloc_no_fail(sizeof(class __objc_anonymous_block_MyBlock_array_trans______2 ):unsigned long ) [line 40]\n *&__objc_anonymous_block_MyBlock_array_trans______2:class __objc_anonymous_block_MyBlock_array_trans______2 =n$42 [line 40]\n *&enumerateObjectsUsingBlock:_fn_ (*)=(_fun___objc_anonymous_block_MyBlock_array_trans______2) [line 40]\n REMOVE_TEMPS(n$42); [line 40]\n " shape="box"] +52 [label="52: DeclStmt \n DECLARE_LOCALS(&__objc_anonymous_block_MyBlock_array_trans______2); [line 40]\n n$42=_fun___objc_alloc_no_fail(sizeof(class __objc_anonymous_block_MyBlock_array_trans______2 ):unsigned long ) [line 40]\n *&__objc_anonymous_block_MyBlock_array_trans______2:class __objc_anonymous_block_MyBlock_array_trans______2 =n$42 [line 40]\n *&enumerateObjectsUsingBlock:_fn_ (*)=(_fun___objc_anonymous_block_MyBlock_array_trans______2) [line 39]\n REMOVE_TEMPS(n$42); [line 39]\n " shape="box"] 52 -> 45 ;