From 80c82c0caeec110e36c594848e68b47b294798a2 Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Fri, 26 Aug 2016 13:06:52 -0700 Subject: [PATCH] Adapt Infer to the new changes introduced by the upgrade to Clang 4.0 Reviewed By: akotulski Differential Revision: D3757013 fbshipit-source-id: 6abe6b1 --- facebook-clang-plugins | 2 +- .../filter_args_and_run_fcp_clang.sh | 2 +- infer/models/c/src/libc_basic.c | 17 ++++++++++++----- infer/src/clang/ast_expressions.ml | 3 ++- infer/src/clang/cFrontend_errors.ml | 2 +- infer/src/clang/cTrans.ml | 9 +++++---- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 0a3172fa8..e265f1c64 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 0a3172fa8d00279b6bb98bedb12bd6cade4c4424 +Subproject commit e265f1c643f4cc3db1c252ed9c04c97b62f7474e diff --git a/infer/lib/clang_wrappers/filter_args_and_run_fcp_clang.sh b/infer/lib/clang_wrappers/filter_args_and_run_fcp_clang.sh index c98e292e0..5878881eb 100755 --- a/infer/lib/clang_wrappers/filter_args_and_run_fcp_clang.sh +++ b/infer/lib/clang_wrappers/filter_args_and_run_fcp_clang.sh @@ -13,7 +13,7 @@ CLANG_COMPILER="${SCRIPT_DIR}/../../../facebook-clang-plugins/clang/install/bin/ # path to infer's clang internal headers. CLANG_INCLUDE_TO_REPLACE="${FCP_CLANG_INCLUDE_TO_REPLACE}" -CLANG_LIB_INCLUDE="${SCRIPT_DIR}/../../../facebook-clang-plugins/clang/install/lib/clang/3.8.0/include" +CLANG_LIB_INCLUDE="${SCRIPT_DIR}/../../../facebook-clang-plugins/clang/install/lib/clang/4.0.0/include" if [ "${0%++}" != "$0" ]; then XX="++"; else XX=""; fi diff --git a/infer/models/c/src/libc_basic.c b/infer/models/c/src/libc_basic.c index f6f52057d..293b14501 100644 --- a/infer/models/c/src/libc_basic.c +++ b/infer/models/c/src/libc_basic.c @@ -77,6 +77,13 @@ struct __dirstream { }; #endif +// this condition checks whether to use C++ const-overloads of C functions +// for example strchr. +#if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || \ + defined(_LIBCPP_PREFERRED_OVERLOAD) +#define INFER_USE_CPP_CONST_OVERLOAD +#endif + // modelling of errno // errno expands to different function calls on mac or other systems // the function call returns the address of a global variable called "errno" @@ -131,7 +138,7 @@ char* strcat(char* s1, const char* s2) { // The string s must be allocated // nondeterministically return 0 or a pointer inside the buffer -#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifndef INFER_USE_CPP_CONST_OVERLOAD char* strchr(const char* s, int c) { #else // This overload is commented out on purpose. @@ -160,7 +167,7 @@ char* strchr(char* s, int c) throw() { } // modelled like strchr -#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifndef INFER_USE_CPP_CONST_OVERLOAD char* strrchr(const char* s, int c) { return strchr(s, c); } #else // This overload is commented out on purpose. Look at strchr() for more info. @@ -242,7 +249,7 @@ char* strncpy(char* s1, const char* s2, size_t n) { return s1; } -#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifndef INFER_USE_CPP_CONST_OVERLOAD char* strpbrk(const char* s1, const char* s2) { #else // This overload is commented out on purpose. Look at strchr() for more info. @@ -279,7 +286,7 @@ size_t strspn(const char* s1, const char* s2) { return res; } -#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifndef INFER_USE_CPP_CONST_OVERLOAD char* strstr(const char* s1, const char* s2) { #else // This overload is commented out on purpose. Look at strchr() for more info. @@ -343,7 +350,7 @@ char* strupr(char* s) { // the array s must be allocated // n should not be greater than the size of s // nondeterministically return 0 or a pointer within the first n elements of s -#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifndef INFER_USE_CPP_CONST_OVERLOAD void* memchr(const void* s, int c, size_t n) { #else // This overload is commented out on purpose. Look at strchr() for more info. diff --git a/infer/src/clang/ast_expressions.ml b/infer/src/clang/ast_expressions.ml index bc1b81c04..cc0fcd1bc 100644 --- a/infer/src/clang/ast_expressions.ml +++ b/infer/src/clang/ast_expressions.ml @@ -566,7 +566,8 @@ let translate_block_enumerate block_name stmt_info stmt_list ei = let unary_op = Clang_ast_t.UnaryOperator (fresh_stmt_info stmt_info, [stop_cast], ei, { Clang_ast_t.uoi_kind = `Deref; uoi_is_postfix = true }) in let cond = create_implicit_cast_expr (fresh_stmt_info stmt_info) [unary_op] bool_tp `LValueToRValue in let break_stmt = Clang_ast_t.BreakStmt (fresh_stmt_info stmt_info, []) in - Clang_ast_t.IfStmt (fresh_stmt_info stmt_info, [dummy_stmt (); cond; break_stmt; dummy_stmt ()]) in + Clang_ast_t.IfStmt + (fresh_stmt_info stmt_info, [dummy_stmt(); dummy_stmt (); cond; break_stmt; dummy_stmt ()]) in let translate params array_cast_decl_ref_exp block_decl block_tp = match params with diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 4d4759c18..3a490cc8b 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -135,7 +135,7 @@ let run_frontend_checkers_on_stmt context cfg cg instr = invoke_set_of_checkers call_captured_vars_checker context cfg cg key captured_vars_checker_list; context - | IfStmt (stmt_info, _ :: cond :: _) -> + | IfStmt (stmt_info, _ :: _ :: cond :: _) -> let call_checker = checker_for_if_stmt stmt_info [cond] in let key = Ast_utils.generate_key_stmt cond in invoke_set_of_checkers call_checker context cfg cg key if_stmt_checker_list; diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 04f930fb5..3853e17ae 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -1327,7 +1327,7 @@ struct let prune_nodes' = if branch then prune_nodes_t else prune_nodes_f in IList.iter (fun n -> Cfg.Node.set_succs_exn context.cfg n nodes_branch []) prune_nodes' in (match stmt_list with - | [decl_stmt; cond; stmt1; stmt2] -> + | [_; decl_stmt; cond; stmt1; stmt2] -> (* set the flat to inform that we are translating a condition of a if *) let continuation' = mk_cond_continuation trans_state.continuation in let trans_state'' = { trans_state with @@ -1353,7 +1353,7 @@ struct let sil_loc = CLocation.get_sil_location stmt_info context in let open Clang_ast_t in match switch_stmt_list with - | [decl_stmt; cond; CompoundStmt(stmt_info, stmt_list)] -> + | [_; decl_stmt; cond; CompoundStmt(stmt_info, stmt_list)] -> let trans_state_pri = PriorityNode.try_claim_priority_node trans_state stmt_info in let trans_state' ={ trans_state_pri with succ_nodes = []} in let res_trans_cond_tmp = instruction trans_state' cond in @@ -1598,11 +1598,12 @@ struct and cxxForRangeStmt_trans trans_state stmt_info stmt_list = let open Clang_ast_t in match stmt_list with - | [iterator_decl; initial_cond; exit_cond; increment; assign_current_index; loop_body] -> + | [iterator_decl; begin_stmt; end_stmt; exit_cond; increment; assign_current_index; loop_body] -> let loop_body' = CompoundStmt (stmt_info, [assign_current_index; loop_body]) in let null_stmt = NullStmt (stmt_info, []) in + let beginend_stmt = CompoundStmt (stmt_info, [begin_stmt; end_stmt]) in let for_loop = - ForStmt (stmt_info, [initial_cond; null_stmt; exit_cond; increment; loop_body']) in + ForStmt (stmt_info, [beginend_stmt; null_stmt; exit_cond; increment; loop_body']) in instruction trans_state (CompoundStmt (stmt_info, [iterator_decl; for_loop])) | _ -> assert false