From 1a19cd5e2d7c7296fe045b8b342f9337466ea15c Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 30 May 2019 04:08:54 -0700 Subject: [PATCH] [clang] change `offsetof()` test Summary: In its new form it actually tests that infer takes the correct branch. Reviewed By: mbouaziz Differential Revision: D15494297 fbshipit-source-id: 7b9bb8f75 --- infer/tests/codetoanalyze/c/errors/issues.exp | 2 +- .../c/frontend/offsetof_expr/offsetof_expr.c | 7 +++-- .../offsetof_expr/offsetof_expr.c.dot | 26 ++++++++----------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/infer/tests/codetoanalyze/c/errors/issues.exp b/infer/tests/codetoanalyze/c/errors/issues.exp index 24d19d0e1..581a9bcc6 100644 --- a/infer/tests/codetoanalyze/c/errors/issues.exp +++ b/infer/tests/codetoanalyze/c/errors/issues.exp @@ -100,6 +100,6 @@ codetoanalyze/c/errors/resource_leaks/leak.c, fileNotClosed, 5, RESOURCE_LEAK, n codetoanalyze/c/errors/resource_leaks/leak.c, socketNotClosed, 5, RESOURCE_LEAK, no_bucket codetoanalyze/c/errors/sizeof/sizeof_706.c, sentinel_bad, 0, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/frontend/enumeration/other_enum.c, other_enum_test, 4, DIVIDE_BY_ZERO, no_bucket -codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c, test_offsetof_expr, 5, DIVIDE_BY_ZERO, no_bucket +codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c, test_offsetof_expr, 3, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c, vaarg_foo, 6, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c, vaarg_foo, 8, DIVIDE_BY_ZERO, no_bucket diff --git a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c index 0dc3625af..f4d3e935f 100644 --- a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c +++ b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c @@ -15,9 +15,8 @@ struct address { int test_offsetof_expr() { int i = offsetof(struct address, v2); - if (i == 9) { - return 9 / 0; - } else { - return 4 / 0; + if (i == 2) { + return 1 / 0; } + return 42; } diff --git a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot index 63e9122c2..ff140ce54 100644 --- a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot @@ -3,41 +3,37 @@ digraph cfg { "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_1" [label="1: Start test_offsetof_expr\nFormals: \nLocals: i:int \n " color=yellow style=filled] - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_1" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_10" ; + "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_1" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" ; "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_2" [label="2: Exit test_offsetof_expr \n " color=yellow style=filled] -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_3" [label="3: + \n " ] +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_3" [label="3: Return Stmt \n *&return:int=42 [line 21, column 3]\n APPLY_ABSTRACTION; [line 21, column 3]\n " shape="box"] - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_3" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" [label="4: between_join_and_exit \n APPLY_ABSTRACTION; [line 18, column 3]\n " shape="box"] + "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_3" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_2" ; +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" [label="4: + \n " ] - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_2" ; + "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_3" ; "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_5" [label="5: BinaryOperatorStmt: EQ \n n$0=*&i:int [line 18, column 7]\n NULLIFY(&i); [line 18, column 7]\n EXIT_SCOPE(i); [line 18, column 7]\n " shape="box"] "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_5" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_6" ; "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_5" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_7" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_6" [label="6: Prune (true branch, if) \n PRUNE((n$0 == 9), true); [line 18, column 7]\n EXIT_SCOPE(n$0); [line 18, column 7]\n " shape="invhouse"] +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_6" [label="6: Prune (true branch, if) \n PRUNE((n$0 == 2), true); [line 18, column 7]\n EXIT_SCOPE(n$0); [line 18, column 7]\n " shape="invhouse"] "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_6" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_8" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_7" [label="7: Prune (false branch, if) \n PRUNE(!(n$0 == 9), false); [line 18, column 7]\n EXIT_SCOPE(n$0); [line 18, column 7]\n " shape="invhouse"] +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_7" [label="7: Prune (false branch, if) \n PRUNE(!(n$0 == 2), false); [line 18, column 7]\n EXIT_SCOPE(n$0); [line 18, column 7]\n " shape="invhouse"] - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_7" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_8" [label="8: Return Stmt \n *&return:int=(9 / 0) [line 19, column 5]\n APPLY_ABSTRACTION; [line 19, column 5]\n " shape="box"] + "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_7" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_4" ; +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_8" [label="8: Return Stmt \n *&return:int=(1 / 0) [line 19, column 5]\n APPLY_ABSTRACTION; [line 19, column 5]\n " shape="box"] "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_8" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_2" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" [label="9: Return Stmt \n *&return:int=(4 / 0) [line 21, column 5]\n APPLY_ABSTRACTION; [line 21, column 5]\n " shape="box"] +"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" [label="9: DeclStmt \n VARIABLE_DECLARED(i:int); [line 17, column 3]\n *&i:int=2 [line 17, column 3]\n " shape="box"] - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_2" ; -"test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_10" [label="10: DeclStmt \n VARIABLE_DECLARED(i:int); [line 17, column 3]\n *&i:int=2 [line 17, column 3]\n " shape="box"] - - - "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_10" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_5" ; + "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_9" -> "test_offsetof_expr.8f3e634fd0f68dff5e4bfedc8f65a55f_5" ; }