Summary: public Translate CXXConstructExpr that are parts of variable initialization. Reviewed By: dulmarod Differential Revision: D2570750 fb-gh-sync-id: 708a457master
							parent
							
								
									ae49cacee8
								
							
						
					
					
						commit
						a9bdf2b291
					
				| @ -0,0 +1,25 @@ | |||||||
|  | /*
 | ||||||
|  | * Copyright (c) 2015 - 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. | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | class X { | ||||||
|  |   int f; | ||||||
|  | public: | ||||||
|  |   X(int a, int b = 0); | ||||||
|  |   int div() { return 1 / f; } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | X::X(int a, int b) { | ||||||
|  |   f = a + b; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void test() { | ||||||
|  |   X x1(0); | ||||||
|  |   X x2(1); | ||||||
|  |   X x3(0, 1); | ||||||
|  | } | ||||||
| @ -0,0 +1,43 @@ | |||||||
|  | digraph iCFG { | ||||||
|  | 11 [label="11:  Call _fun_X_X \n   _fun_X_X(&x1:class X *,0:int ,0:int ) [line 22]\n " shape="box"] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 11 -> 10 ; | ||||||
|  | 10 [label="10:  Call _fun_X_X \n   _fun_X_X(&x2:class X *,1:int ,0:int ) [line 23]\n " shape="box"] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 10 -> 9 ; | ||||||
|  | 9 [label="9:  Call _fun_X_X \n   _fun_X_X(&x3:class X *,0:int ,1:int ) [line 24]\n  NULLIFY(&x1,false); [line 24]\n  NULLIFY(&x2,false); [line 24]\n  NULLIFY(&x3,false); [line 24]\n  APPLY_ABSTRACTION; [line 24]\n " shape="box"] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 9 -> 8 ; | ||||||
|  | 8 [label="8: Exit test \n  " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 7 [label="7: Start test\nFormals: \nLocals:  x3:class X  x2:class X  x1:class X  \n   DECLARE_LOCALS(&return,&x3,&x2,&x1); [line 21]\n " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 7 -> 11 ; | ||||||
|  | 6 [label="6:  BinaryOperatorStmt: Assign \n   n$0=*&this:class X * [line 18]\n  n$1=*&a:int  [line 18]\n  n$2=*&b:int  [line 18]\n  *n$0.f:int =(n$1 + n$2) [line 18]\n  REMOVE_TEMPS(n$0,n$1,n$2); [line 18]\n  NULLIFY(&a,false); [line 18]\n  NULLIFY(&b,false); [line 18]\n  NULLIFY(&this,false); [line 18]\n  APPLY_ABSTRACTION; [line 18]\n " shape="box"] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 6 -> 5 ; | ||||||
|  | 5 [label="5: Exit X_X \n  " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 4 [label="4: Start X_X\nFormals:  this:class X * a:int  b:int \nLocals:  \n   DECLARE_LOCALS(&return); [line 17]\n " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 4 -> 6 ; | ||||||
|  | 3 [label="3:  Return Stmt \n   n$0=*&this:class X * [line 14]\n  n$1=*n$0.f:int  [line 14]\n  *&return:int =(1 / n$1) [line 14]\n  REMOVE_TEMPS(n$0,n$1); [line 14]\n  NULLIFY(&this,false); [line 14]\n  APPLY_ABSTRACTION; [line 14]\n " shape="box"] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 3 -> 2 ; | ||||||
|  | 2 [label="2: Exit X_div \n  " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 1 [label="1: Start X_div\nFormals:  this:class X *\nLocals:  \n   DECLARE_LOCALS(&return); [line 14]\n " color=yellow style=filled] | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
|  | 	 1 -> 3 ; | ||||||
|  | } | ||||||
| @ -0,0 +1,89 @@ | |||||||
|  | /* | ||||||
|  | * Copyright (c) 2015 - 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. | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | package endtoend.cpp; | ||||||
|  | 
 | ||||||
|  | import static org.hamcrest.MatcherAssert.assertThat; | ||||||
|  | import static utils.matchers.ResultContainsErrorInMethod.contains; | ||||||
|  | import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain; | ||||||
|  | 
 | ||||||
|  | import com.google.common.collect.ImmutableList; | ||||||
|  | 
 | ||||||
|  | import org.junit.BeforeClass; | ||||||
|  | import org.junit.ClassRule; | ||||||
|  | import org.junit.Test; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | 
 | ||||||
|  | import utils.DebuggableTemporaryFolder; | ||||||
|  | import utils.InferException; | ||||||
|  | import utils.InferResults; | ||||||
|  | import utils.InferRunner; | ||||||
|  | 
 | ||||||
|  | public class ConstructorWithBodyTest { | ||||||
|  | 
 | ||||||
|  |   public static final String FILE = | ||||||
|  |       "infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_with_body.cpp"; | ||||||
|  | 
 | ||||||
|  |   private static ImmutableList<String> inferCmd; | ||||||
|  | 
 | ||||||
|  |   public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; | ||||||
|  | 
 | ||||||
|  |   @ClassRule | ||||||
|  |   public static DebuggableTemporaryFolder folder = | ||||||
|  |       new DebuggableTemporaryFolder(); | ||||||
|  | 
 | ||||||
|  |   @BeforeClass | ||||||
|  |   public static void runInfer() throws InterruptedException, IOException { | ||||||
|  |     inferCmd = InferRunner.createCPPInferCommand(folder, FILE); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   public void whenInferRunsOnConstructorWithBodyDiv0ErrorIsFound() | ||||||
|  |       throws InterruptedException, IOException, InferException { | ||||||
|  |     InferResults inferResults = InferRunner.runInferCPP(inferCmd); | ||||||
|  |     String[] procedures = { | ||||||
|  |         "test_div0", | ||||||
|  |         "test_div0_default_constructor", | ||||||
|  |     }; | ||||||
|  |     assertThat( | ||||||
|  |         "Results should contain null pointer dereference error", | ||||||
|  |         inferResults, | ||||||
|  |         contains( | ||||||
|  |             DIVIDE_BY_ZERO, | ||||||
|  |             FILE, | ||||||
|  |             "test_div0" | ||||||
|  |         ) | ||||||
|  |     ); | ||||||
|  |     assertThat( | ||||||
|  |         "Results should contain null pointer dereference error", | ||||||
|  |         inferResults, | ||||||
|  |         contains( | ||||||
|  |             DIVIDE_BY_ZERO, | ||||||
|  |             FILE, | ||||||
|  |             "test_div0_default_constructor" | ||||||
|  |         ) | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   public void whenInferRunsOnConstructorWithBodyDiv1ErrorIsNotFound() | ||||||
|  |       throws InterruptedException, IOException, InferException { | ||||||
|  |     InferResults inferResults = InferRunner.runInferCPP(inferCmd); | ||||||
|  |     assertThat( | ||||||
|  |         "Results should not contain null pointer dereference error", | ||||||
|  |         inferResults, | ||||||
|  |         doesNotContain( | ||||||
|  |             DIVIDE_BY_ZERO, | ||||||
|  |             FILE, | ||||||
|  |             "test_div1" | ||||||
|  |         ) | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue