From e4a0e9bbf7c6cd43f0858f138ee388e3a10eb358 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 23 Feb 2016 05:25:28 -0800 Subject: [PATCH] Translate CXXDefaultInitExpr Summary:public Do same thing we do to CXXDefaultArgExpr Reviewed By: dulmarod Differential Revision: D2954128 fb-gh-sync-id: 2c92c16 shipit-source-id: 2c92c16 --- facebook-clang-plugins | 2 +- infer/src/clang/cTrans.ml | 9 +-- .../constructors/default_field_init.cpp | 25 +++++++ .../constructors/default_field_init.cpp.dot | 70 +++++++++++++++++++ .../tests/frontend/cpp/ConstructorsTest.java | 6 ++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 60b10ef73..cadf02f4f 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 60b10ef73606e814cf87c08e5c0d263dc1f9fb8c +Subproject commit cadf02f4f3918062d8c51870af1beadca6140af8 diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index bbf97061c..5339fa349 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2034,8 +2034,8 @@ struct stmt_info all_res_trans in { res_trans_to_parent with exps = [(res_ex, cast_type)] } - and cxxDefaultArgExpr_trans trans_state default_arg_info = - match default_arg_info.Clang_ast_t.xdaei_init_expr with + and cxxDefaultExpr_trans trans_state default_expr_info = + match default_expr_info.Clang_ast_t.xdaei_init_expr with | Some exp -> instruction trans_state exp | None -> assert false @@ -2278,8 +2278,9 @@ struct | CXXDynamicCastExpr (stmt_info, stmts, _, _, type_ptr, _) -> cxxDynamicCastExpr_trans trans_state stmt_info stmts type_ptr - | CXXDefaultArgExpr (_, _, _, default_arg_info) -> - cxxDefaultArgExpr_trans trans_state default_arg_info + | CXXDefaultArgExpr (_, _, _, default_expr_info) + | CXXDefaultInitExpr (_, _, _, default_expr_info) -> + cxxDefaultExpr_trans trans_state default_expr_info | s -> (Printing.log_stats "\n!!!!WARNING: found statement %s. \nACTION REQUIRED: Translation need to be defined. Statement ignored.... \n" diff --git a/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp b/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp new file mode 100644 index 000000000..a52091022 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 - 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. + */ + +struct X { + int a = -1; + int b{-2}; + int c{}; // doesn't work yet + int d; + X() = default; + X(int a, int b) : a(a + b) {} +}; + +struct Y { + X x1{1, 2}; + X x2{}; + X x3; +}; + +void test() { Y y; } 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 new file mode 100644 index 000000000..4eb28928b --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/constructors/default_field_init.cpp.dot @@ -0,0 +1,70 @@ +digraph iCFG { +18 [label="18: DeclStmt \n _fun_Y_Y(&y:class Y *) [line 25]\n NULLIFY(&y,false); [line 25]\n APPLY_ABSTRACTION; [line 25]\n " shape="box"] + + + 18 -> 17 ; +17 [label="17: Exit test \n " color=yellow style=filled] + + +16 [label="16: Start test\nFormals: \nLocals: y:class Y \n DECLARE_LOCALS(&return,&y); [line 25]\n " color=yellow style=filled] + + + 16 -> 18 ; +15 [label="15: Constructor Init \n n$2=*&this:class Y * [line 20]\n _fun_X_X(n$2.x1:class X *,1:int ,2:int ) [line 20]\n REMOVE_TEMPS(n$2); [line 20]\n " shape="box"] + + + 15 -> 14 ; +14 [label="14: Constructor Init \n n$1=*&this:class Y * [line 21]\n _fun_X_X(n$1.x2:class X *) [line 21]\n REMOVE_TEMPS(n$1); [line 21]\n " shape="box"] + + + 14 -> 13 ; +13 [label="13: Constructor Init \n n$0=*&this:class Y * [line 19]\n _fun_X_X(n$0.x3:class X *) [line 19]\n REMOVE_TEMPS(n$0); [line 19]\n NULLIFY(&this,false); [line 19]\n APPLY_ABSTRACTION; [line 19]\n " shape="box"] + + + 13 -> 12 ; +12 [label="12: Exit Y_Y \n " color=yellow style=filled] + + +11 [label="11: Start Y_Y\nFormals: this:class Y *\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled] + + + 11 -> 15 ; +10 [label="10: Constructor Init \n n$2=*&this:class X * [line 16]\n n$3=*&a:int [line 16]\n n$4=*&b:int [line 16]\n *n$2.a:int =(n$3 + n$4) [line 16]\n REMOVE_TEMPS(n$2,n$3,n$4); [line 16]\n NULLIFY(&a,false); [line 16]\n NULLIFY(&b,false); [line 16]\n " shape="box"] + + + 10 -> 9 ; +9 [label="9: Constructor Init \n n$1=*&this:class X * [line 12]\n *n$1.b:int =-2 [line 12]\n REMOVE_TEMPS(n$1); [line 12]\n " shape="box"] + + + 9 -> 8 ; +8 [label="8: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =-1 [line 16]\n REMOVE_TEMPS(n$0); [line 16]\n NULLIFY(&this,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"] + + + 8 -> 7 ; +7 [label="7: Exit X_X \n " color=yellow style=filled] + + +6 [label="6: Start X_X\nFormals: this:class X * a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled] + + + 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 -> 4 ; +4 [label="4: Constructor Init \n n$1=*&this:class X * [line 12]\n *n$1.b:int =-2 [line 12]\n REMOVE_TEMPS(n$1); [line 12]\n " shape="box"] + + + 4 -> 3 ; +3 [label="3: Constructor Init \n n$0=*&this:class X * [line 13]\n *n$0.c:int =-1 [line 15]\n REMOVE_TEMPS(n$0); [line 15]\n NULLIFY(&this,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit X_X \n " color=yellow style=filled] + + +1 [label="1: Start X_X\nFormals: this:class X *\nLocals: \n DECLARE_LOCALS(&return); [line 15]\n " color=yellow style=filled] + + + 1 -> 5 ; +} diff --git a/infer/tests/frontend/cpp/ConstructorsTest.java b/infer/tests/frontend/cpp/ConstructorsTest.java index 18ac53134..24c48ae11 100644 --- a/infer/tests/frontend/cpp/ConstructorsTest.java +++ b/infer/tests/frontend/cpp/ConstructorsTest.java @@ -58,4 +58,10 @@ public class ConstructorsTest { throws InterruptedException, IOException, InferException { frontendTest("copy_move_constructor.cpp"); } + + @Test + public void testDefaultFieldInitDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("default_field_init.cpp"); + } }