diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 3267da67a..1b6e6183a 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 3267da67afe81c99394f22226bad294922de0875 +Subproject commit 1b6e6183affe497bcbe3cb6c37c3065d4ecbb91e diff --git a/infer/src/backend/utils.ml b/infer/src/backend/utils.ml index 09262b28b..e7b92102a 100644 --- a/infer/src/backend/utils.ml +++ b/infer/src/backend/utils.ml @@ -75,6 +75,8 @@ let fst3 (x,_,_) = x let snd3 (_,x,_) = x let trd3 (_,_,x) = x +let int_of_bool b = if b then 1 else 0 + (** {2 Useful Modules} *) (** Set of integers *) diff --git a/infer/src/backend/utils.mli b/infer/src/backend/utils.mli index 05fe17581..ff0ff6fea 100644 --- a/infer/src/backend/utils.mli +++ b/infer/src/backend/utils.mli @@ -71,6 +71,9 @@ val snd3 : 'a * 'b * 'c -> 'b (** Return the third component of a triple. *) val trd3 : 'a * 'b * 'c -> 'c +(** Convert a bool into an int *) +val int_of_bool : bool -> int + (** {2 Useful Modules} *) (** Set of integers *) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 7029844e7..0e480798f 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2585,6 +2585,10 @@ struct | AttributedStmt (_, stmts, attrs) -> attributedStmt_trans trans_state stmts attrs + | TypeTraitExpr (_, _, expr_info, type_trait_info) -> + let b = type_trait_info.Clang_ast_t.xtti_value in + characterLiteral_trans trans_state expr_info (Utils.int_of_bool b) + | 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/types/type_trait_expr.cpp b/infer/tests/codetoanalyze/cpp/frontend/types/type_trait_expr.cpp new file mode 100644 index 000000000..07e4810ed --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/types/type_trait_expr.cpp @@ -0,0 +1,12 @@ +/* + * 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. + */ + +int is_trivial_example() { return __is_trivial(int); } + +int is_pointer_example() { return __is_pointer(int); } diff --git a/infer/tests/codetoanalyze/cpp/frontend/types/type_trait_expr.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/types/type_trait_expr.cpp.dot new file mode 100644 index 000000000..217d61448 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/types/type_trait_expr.cpp.dot @@ -0,0 +1,25 @@ +/* @generated */ +digraph iCFG { +6 [label="6: Return Stmt \n *&return:int =0 [line 12]\n " shape="box"] + + + 6 -> 5 ; +5 [label="5: Exit is_pointer_example \n " color=yellow style=filled] + + +4 [label="4: Start is_pointer_example\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled] + + + 4 -> 6 ; +3 [label="3: Return Stmt \n *&return:int =1 [line 10]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit is_trivial_example \n " color=yellow style=filled] + + +1 [label="1: Start is_trivial_example\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/frontend/cpp/TypesTest.java b/infer/tests/frontend/cpp/TypesTest.java index 0cd22c8ae..68b58df8d 100644 --- a/infer/tests/frontend/cpp/TypesTest.java +++ b/infer/tests/frontend/cpp/TypesTest.java @@ -40,4 +40,10 @@ public class TypesTest { throws InterruptedException, IOException, InferException { frontendTest("struct_pass_by_value.cpp"); } + + @Test + public void typeTraitExprDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("type_trait_expr.cpp"); + } }