From edbd7854b230ff1130ae84c0ab7b6d4e48791155 Mon Sep 17 00:00:00 2001 From: Dulma Rodriguez Date: Mon, 7 Mar 2016 08:59:33 -0800 Subject: [PATCH] Translate SizeOfPackExpr Reviewed By: akotulski Differential Revision: D3018506 fb-gh-sync-id: 11eca37 shipit-source-id: 11eca37 --- infer/src/clang/cTrans.ml | 3 +- .../cpp/frontend/templates/sizeof_pack.cpp | 23 ++++++++++ .../frontend/templates/sizeof_pack.cpp.dot | 45 +++++++++++++++++++ infer/tests/frontend/cpp/TemplatesTest.java | 6 +++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp.dot diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 2fc5b416d..265b56488 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2272,7 +2272,8 @@ struct | ImplicitValueInitExpr (_, _, expr_info) -> implicitValueInitExpr_trans trans_state expr_info - | GenericSelectionExpr _ -> (* to be fixed when we dump the right info in the ast *) + | GenericSelectionExpr _ (* to be fixed when we dump the right info in the ast *) + | SizeOfPackExpr _ -> { empty_res_trans with exps = [(Sil.exp_get_undefined false, Sil.Tvoid)] } | GCCAsmStmt (stmt_info, stmts) -> diff --git a/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp b/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp new file mode 100644 index 000000000..108bbc9e5 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp @@ -0,0 +1,23 @@ +/* + * 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 MyHasher { + static int hash(int t) { return 1; } +}; + +template +int hash_combine_generic(const T& t, const Ts&... ts) { + int seed = Hasher::hash(t); + if (sizeof...(ts) == 0) { + return seed; + } + return 0; +} + +int test = hash_combine_generic(0, 0, 0); diff --git a/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp.dot new file mode 100644 index 000000000..818ca6980 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/templates/sizeof_pack.cpp.dot @@ -0,0 +1,45 @@ +digraph iCFG { +11 [label="11: DeclStmt \n n$1=*&t:int & [line 16]\n n$2=*n$1:int [line 16]\n n$3=_fun_MyHasher_hash(n$2:int ) [line 16]\n *&seed:int =n$3 [line 16]\n REMOVE_TEMPS(n$1,n$2,n$3); [line 16]\n NULLIFY(&t,false); [line 16]\n " shape="box"] + + + 11 -> 8 ; + 11 -> 9 ; +10 [label="10: Return Stmt \n n$0=*&seed:int [line 18]\n *&return:int =n$0 [line 18]\n REMOVE_TEMPS(n$0); [line 18]\n NULLIFY(&seed,false); [line 18]\n APPLY_ABSTRACTION; [line 18]\n " shape="box"] + + + 10 -> 5 ; +9 [label="9: Prune (false branch) \n PRUNE(((_t$0 == 0) == 0), false); [line 17]\n " shape="invhouse"] + + + 9 -> 7 ; +8 [label="8: Prune (true branch) \n PRUNE(((_t$0 == 0) != 0), true); [line 17]\n " shape="invhouse"] + + + 8 -> 10 ; +7 [label="7: + \n " ] + + + 7 -> 6 ; +6 [label="6: Return Stmt \n NULLIFY(&seed,false); [line 20]\n *&return:int =0 [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] + + + 6 -> 5 ; +5 [label="5: Exit hash_combine_generic \n " color=yellow style=filled] + + +4 [label="4: Start hash_combine_generic\nFormals: t:int & ts:int & ts:int &\nLocals: seed:int \n DECLARE_LOCALS(&return,&seed); [line 15]\n NULLIFY(&seed,false); [line 15]\n NULLIFY(&ts,false); [line 15]\n " color=yellow style=filled] + + + 4 -> 11 ; +3 [label="3: Return Stmt \n *&return:int =1 [line 11]\n APPLY_ABSTRACTION; [line 11]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit MyHasher_hash \n " color=yellow style=filled] + + +1 [label="1: Start MyHasher_hash\nFormals: t:int \nLocals: \n DECLARE_LOCALS(&return); [line 11]\n NULLIFY(&t,false); [line 11]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/frontend/cpp/TemplatesTest.java b/infer/tests/frontend/cpp/TemplatesTest.java index a2f549587..2a79119dc 100644 --- a/infer/tests/frontend/cpp/TemplatesTest.java +++ b/infer/tests/frontend/cpp/TemplatesTest.java @@ -52,4 +52,10 @@ public class TemplatesTest { throws InterruptedException, IOException, InferException { frontendTest("method.cpp"); } + + @Test + public void testSizeofPackDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("sizeof_pack.cpp"); + } }