diff --git a/facebook-clang-plugins b/facebook-clang-plugins index e1dce5cb9..4c6534821 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit e1dce5cb9676dfa0bf2f54111f74e54b6f9e4b88 +Subproject commit 4c653482100360ff0c580e39e456dcb0a74b628c diff --git a/infer/tests/codetoanalyze/cpp/errors/Makefile b/infer/tests/codetoanalyze/cpp/errors/Makefile index 611b88b03..5d1d70c42 100644 --- a/infer/tests/codetoanalyze/cpp/errors/Makefile +++ b/infer/tests/codetoanalyze/cpp/errors/Makefile @@ -32,6 +32,7 @@ SOURCES = \ shared/constructors/constructor_with_body.cpp \ shared/constructors/copy_move_constructor.cpp \ shared/constructors/temp_object.cpp \ + shared/constructors/copy_array_field.cpp \ shared/exceptions/Exceptions.cpp \ $(wildcard shared/lambda/*.cpp) \ shared/methods/conversion_operator.cpp \ diff --git a/infer/tests/codetoanalyze/cpp/errors/issues.exp b/infer/tests/codetoanalyze/cpp/errors/issues.exp index 7277ca700..59c82d438 100644 --- a/infer/tests/codetoanalyze/cpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/cpp/errors/issues.exp @@ -185,6 +185,8 @@ codetoanalyze/cpp/shared/constructors/constructor_new.cpp, constructor_new::int_ codetoanalyze/cpp/shared/constructors/constructor_new.cpp, constructor_new::matrix_of_person, 2, MEMORY_LEAK, [start of procedure constructor_new::matrix_of_person(),start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person,start of procedure Person,return from a call to constructor_new::Person_Person] codetoanalyze/cpp/shared/constructors/constructor_with_body.cpp, constructor_with_body::test_div0, 2, DIVIDE_BY_ZERO, [start of procedure constructor_with_body::test_div0(),start of procedure X,start of procedure init,return from a call to constructor_with_body::X_init,return from a call to constructor_with_body::X_X,start of procedure div] codetoanalyze/cpp/shared/constructors/constructor_with_body.cpp, constructor_with_body::test_div0_default_constructor, 2, DIVIDE_BY_ZERO, [start of procedure constructor_with_body::test_div0_default_constructor(),start of procedure X,start of procedure init,return from a call to constructor_with_body::X_init,return from a call to constructor_with_body::X_X,start of procedure div] +codetoanalyze/cpp/shared/constructors/copy_array_field.cpp, copy_array_field::X_X, 0, ARRAY_OUT_OF_BOUNDS_L3, [start of procedure X] +codetoanalyze/cpp/shared/constructors/copy_array_field.cpp, copy_array_field::npe, 4, NULL_DEREFERENCE, [start of procedure copy_array_field::npe(),start of procedure X,return from a call to copy_array_field::X_X,start of procedure X,return from a call to copy_array_field::X_X] codetoanalyze/cpp/shared/constructors/copy_move_constructor.cpp, copy_move_constructor::copyX_div0, 4, DIVIDE_BY_ZERO, [start of procedure copy_move_constructor::copyX_div0(),start of procedure X,return from a call to copy_move_constructor::X_X,start of procedure X,return from a call to copy_move_constructor::X_X] codetoanalyze/cpp/shared/constructors/copy_move_constructor.cpp, copy_move_constructor::copyY_div0, 4, DIVIDE_BY_ZERO, [start of procedure copy_move_constructor::copyY_div0(),start of procedure Y,return from a call to copy_move_constructor::Y_Y,start of procedure Y,return from a call to copy_move_constructor::Y_Y] codetoanalyze/cpp/shared/constructors/copy_move_constructor.cpp, copy_move_constructor::moveX_div0, 0, DIVIDE_BY_ZERO, [start of procedure copy_move_constructor::moveX_div0(),start of procedure copy_move_constructor::getX(),start of procedure X,return from a call to copy_move_constructor::X_X,start of procedure X,return from a call to copy_move_constructor::X_X,return from a call to copy_move_constructor::getX] diff --git a/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp b/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp new file mode 100644 index 000000000..b8b2941cc --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 - 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. + */ +namespace copy_array_field { +struct X { + int* p; + int x[10]; // array field +}; + +int npe() { + X x1; + x1.p = 0; + X x2 = x1; // will call default copy constructor + return *x2.p; +} + +int no_npe() { + int a = 0; + X x1; + x1.p = &a; + X x2 = x1; // will call default copy constructor + return *x2.p; +} +} diff --git a/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp.dot b/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp.dot new file mode 100644 index 000000000..a16e3ab4d --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/shared/constructors/copy_array_field.cpp.dot @@ -0,0 +1,75 @@ +/* @generated */ +digraph iCFG { +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_1" [label="1: Start copy_array_field::npe\nFormals: \nLocals: x2:class copy_array_field::X x1:class copy_array_field::X \n DECLARE_LOCALS(&return,&x2,&x1); [line 15]\n " color=yellow style=filled] + + + "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_1" -> "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_6" ; +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_2" [label="2: Exit copy_array_field::npe \n " color=yellow style=filled] + + +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_3" [label="3: Return Stmt \n n$0=*&x2.p:int* [line 19]\n n$1=*n$0:int [line 19]\n *&return:int=n$1 [line 19]\n " shape="box"] + + + "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_3" -> "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_2" ; +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_4" [label="4: DeclStmt \n _fun_copy_array_field::X_X(&x2:class copy_array_field::X*,&x1:class copy_array_field::X&) [line 18]\n " shape="box"] + + + "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_4" -> "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_3" ; +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_5" [label="5: BinaryOperatorStmt: Assign \n *&x1.p:int*=0 [line 17]\n " shape="box"] + + + "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_5" -> "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_4" ; +"copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_6" [label="6: DeclStmt \n _fun_copy_array_field::X_X(&x1:class copy_array_field::X*) [line 16]\n " shape="box"] + + + "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_6" -> "copy_array_field::npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field3npeEv}.34f79bc9982a67b09f43c8e07e8f32e2_5" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_1" [label="1: Start copy_array_field::no_npe\nFormals: \nLocals: x2:class copy_array_field::X x1:class copy_array_field::X a:int \n DECLARE_LOCALS(&return,&x2,&x1,&a); [line 22]\n " color=yellow style=filled] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_1" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_7" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_2" [label="2: Exit copy_array_field::no_npe \n " color=yellow style=filled] + + +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_3" [label="3: Return Stmt \n n$0=*&x2.p:int* [line 27]\n n$1=*n$0:int [line 27]\n *&return:int=n$1 [line 27]\n " shape="box"] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_3" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_2" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_4" [label="4: DeclStmt \n _fun_copy_array_field::X_X(&x2:class copy_array_field::X*,&x1:class copy_array_field::X&) [line 26]\n " shape="box"] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_4" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_3" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_5" [label="5: BinaryOperatorStmt: Assign \n *&x1.p:int*=&a [line 25]\n " shape="box"] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_5" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_4" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_6" [label="6: DeclStmt \n _fun_copy_array_field::X_X(&x1:class copy_array_field::X*) [line 24]\n " shape="box"] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_6" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_5" ; +"copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_7" [label="7: DeclStmt \n *&a:int=0 [line 23]\n " shape="box"] + + + "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_7" -> "copy_array_field::no_npe{d41d8cd98f00b204e9800998ecf8427e_ZN16copy_array_field6no_npeEv}.c7d0652407dba78f69ad18a1b0e951b1_6" ; +"copy_array_field::X_X{_ZN16copy_array_field1XC1Ev}.9b9462bb10985d335d9f5baadb381209_1" [label="1: Start copy_array_field::X_X\nFormals: this:class copy_array_field::X*\nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled] + + + "copy_array_field::X_X{_ZN16copy_array_field1XC1Ev}.9b9462bb10985d335d9f5baadb381209_1" -> "copy_array_field::X_X{_ZN16copy_array_field1XC1Ev}.9b9462bb10985d335d9f5baadb381209_2" ; +"copy_array_field::X_X{_ZN16copy_array_field1XC1Ev}.9b9462bb10985d335d9f5baadb381209_2" [label="2: Exit copy_array_field::X_X \n " color=yellow style=filled] + + +"copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_1" [label="1: Start copy_array_field::X_X\nFormals: this:class copy_array_field::X* __param_0:class copy_array_field::X&\nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled] + + + "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_1" -> "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_4" ; +"copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_2" [label="2: Exit copy_array_field::X_X \n " color=yellow style=filled] + + +"copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_3" [label="3: Constructor Init \n n$0=*&this:class copy_array_field::X* [line 10]\n n$1=*&__param_0:class copy_array_field::X& [line 10]\n n$2=*&__i0:unsigned long [line 10]\n n$3=*n$1.x[n$2]:int [line 10]\n *n$0.x:int=n$3 [line 10]\n " shape="box"] + + + "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_3" -> "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_2" ; +"copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_4" [label="4: Constructor Init \n n$4=*&this:class copy_array_field::X* [line 10]\n n$5=*&__param_0:class copy_array_field::X& [line 10]\n n$6=*n$5.p:int* [line 10]\n *n$4.p:int*=n$6 [line 10]\n " shape="box"] + + + "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_4" -> "copy_array_field::X_X{_ZN16copy_array_field1XC1ERKS0_|constexpr}.33a7a7c3da7e4c81ca4741491f7ac336_3" ; +}