From edc57f70f50a7ef57260147d3c8c13bca952b52d Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Mon, 27 Jun 2016 03:09:44 -0700 Subject: [PATCH] Translate CXXNoexceptExpr Reviewed By: akotulski Differential Revision: D3481942 fbshipit-source-id: ff4df1a --- facebook-clang-plugins | 2 +- infer/src/clang/cTrans.ml | 9 ++++- .../cpp/frontend/exceptions/noexception.cpp | 16 ++++++++ .../frontend/exceptions/noexception.cpp.dot | 39 +++++++++++++++++++ infer/tests/frontend/cpp/ExceptionsTest.java | 6 +++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp.dot diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 1b6e6183a..815fde847 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 1b6e6183affe497bcbe3cb6c37c3065d4ecbb91e +Subproject commit 815fde847bdb2e244c2c9509810601aaeab392f4 diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 0e480798f..eb641a95d 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -369,6 +369,9 @@ struct let exp = Sil.Const (Sil.Cint (IntLit.of_int n)) in { empty_res_trans with exps = [(exp, typ)]} + let booleanValue_trans trans_state expr_info b = + characterLiteral_trans trans_state expr_info (Utils.int_of_bool b) + let floatingLiteral_trans trans_state expr_info float_string = let typ = CTypes_decl.get_type_from_expr_info expr_info trans_state.context.CContext.tenv in let exp = Sil.Const (Sil.Cfloat (float_of_string float_string)) in @@ -2586,8 +2589,10 @@ struct 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) + booleanValue_trans trans_state expr_info type_trait_info.Clang_ast_t.xtti_value + + | CXXNoexceptExpr (_, _, expr_info, cxx_noexcept_expr_info) -> + booleanValue_trans trans_state expr_info cxx_noexcept_expr_info.Clang_ast_t.xnee_value | s -> (Printing.log_stats "\n!!!!WARNING: found statement %s. \nACTION REQUIRED: \ diff --git a/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp b/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp new file mode 100644 index 000000000..0a0c636fb --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp @@ -0,0 +1,16 @@ +/* + * 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. + */ + +void throw1(){}; + +void no_throw() noexcept {}; + +int noexcept_in_no_throw_is_true() { return noexcept(no_throw()); } + +int noexcept_in_throw1_is_false() { return noexcept(throw1()); } diff --git a/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp.dot new file mode 100644 index 000000000..36fa6e863 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/exceptions/noexception.cpp.dot @@ -0,0 +1,39 @@ +/* @generated */ +digraph iCFG { +10 [label="10: Return Stmt \n *&return:int =0 [line 16]\n " shape="box"] + + + 10 -> 9 ; +9 [label="9: Exit noexcept_in_throw1_is_false \n " color=yellow style=filled] + + +8 [label="8: Start noexcept_in_throw1_is_false\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled] + + + 8 -> 10 ; +7 [label="7: Return Stmt \n *&return:int =1 [line 14]\n " shape="box"] + + + 7 -> 6 ; +6 [label="6: Exit noexcept_in_no_throw_is_true \n " color=yellow style=filled] + + +5 [label="5: Start noexcept_in_no_throw_is_true\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 14]\n " color=yellow style=filled] + + + 5 -> 7 ; +4 [label="4: Exit no_throw \n " color=yellow style=filled] + + +3 [label="3: Start no_throw\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled] + + + 3 -> 4 ; +2 [label="2: Exit throw1 \n " color=yellow style=filled] + + +1 [label="1: Start throw1\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled] + + + 1 -> 2 ; +} diff --git a/infer/tests/frontend/cpp/ExceptionsTest.java b/infer/tests/frontend/cpp/ExceptionsTest.java index c9093c5c1..d8989bb24 100644 --- a/infer/tests/frontend/cpp/ExceptionsTest.java +++ b/infer/tests/frontend/cpp/ExceptionsTest.java @@ -35,4 +35,10 @@ public class ExceptionsTest { frontendTest("Exceptions.cpp"); } + @Test + public void testNoExceptionExprDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("noexception.cpp"); + } + }