From 21af28619f3baa970d9c271f590b08ebe090e898 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Mon, 3 Apr 2017 06:04:14 -0700 Subject: [PATCH] [C++] Use annotate attribute instead of deprecated Summary: `__attribute__((annotate("")))` is better way of passing information to the frontend Reviewed By: jberdine Differential Revision: D4818805 fbshipit-source-id: 6e8add2 --- .../cpp/include/infer_model/infer_traits.h | 2 +- infer/src/clang/cTrans.ml | 8 ++++---- .../tests/codetoanalyze/cpp/errors/issues.exp | 20 +++++++++---------- .../{deprecated_hack.cpp => annotate.cpp} | 10 +++++----- ...precated_hack.cpp.dot => annotate.cpp.dot} | 0 5 files changed, 20 insertions(+), 20 deletions(-) rename infer/tests/codetoanalyze/cpp/shared/attributes/{deprecated_hack.cpp => annotate.cpp} (91%) rename infer/tests/codetoanalyze/cpp/shared/attributes/{deprecated_hack.cpp.dot => annotate.cpp.dot} (100%) diff --git a/infer/models/cpp/include/infer_model/infer_traits.h b/infer/models/cpp/include/infer_model/infer_traits.h index 734a707e3..c685674a2 100644 --- a/infer/models/cpp/include/infer_model/infer_traits.h +++ b/infer/models/cpp/include/infer_model/infer_traits.h @@ -17,4 +17,4 @@ class TranslateAsType {}; } // namespace infer_traits #define INFER_MODEL_AS_DEREF_FIRST_ARG \ - __attribute__((deprecated("__infer_replace_with_deref_first_arg"))) {} + __attribute__((annotate("__infer_replace_with_deref_first_arg"))) {} diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index b7e093e33..bb2d7b185 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -438,21 +438,21 @@ struct { empty_res_trans with root_nodes = [root_node']; leaf_nodes = trans_state.succ_nodes } let get_builtin_pname_opt trans_unit_ctx qual_name decl_opt type_ptr = - let get_deprecated_attr_arg decl = + let get_annotate_attr_arg decl = let open Clang_ast_t in let decl_info = Clang_ast_proj.get_decl_tuple decl in - let get_attr_opt = function DeprecatedAttr a -> Some a | _ -> None in + let get_attr_opt = function AnnotateAttr a -> Some a | _ -> None in match List.find_map ~f:get_attr_opt decl_info.di_attributes with | Some attribute_info -> (match attribute_info.ai_parameters with - | [_; arg; _; _; _; _] -> Some arg + | [_; arg; _] -> Some arg | _ -> (* it's not supposed to happen due to hardcoded exporting logic coming from ASTExporter.h in facebook-clang-plugins *) assert false) | None -> None in let name = QualifiedCppName.to_qual_string qual_name in - let function_attr_opt = Option.bind decl_opt get_deprecated_attr_arg in + let function_attr_opt = Option.bind decl_opt get_annotate_attr_arg in match function_attr_opt with | Some attr when CTrans_models.is_modeled_attribute attr -> Some (Typ.Procname.from_string_c_fun attr) diff --git a/infer/tests/codetoanalyze/cpp/errors/issues.exp b/infer/tests/codetoanalyze/cpp/errors/issues.exp index 9d4268ef3..2e4541bf2 100644 --- a/infer/tests/codetoanalyze/cpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/cpp/errors/issues.exp @@ -147,16 +147,16 @@ codetoanalyze/cpp/errors/vector/empty_access.cpp, vector_as_param_by_value_empty codetoanalyze/cpp/errors/vector/empty_access.cpp, vector_as_param_clear, 3, EMPTY_VECTOR_ACCESS, [start of procedure vector_as_param_clear(),start of procedure vector_param_clear(),return from a call to vector_param_clear] codetoanalyze/cpp/errors/vector/empty_access.cpp, vector_as_param_empty, 2, EMPTY_VECTOR_ACCESS, [start of procedure vector_as_param_empty(),start of procedure vector_param_access(),return from a call to vector_param_access] codetoanalyze/cpp/errors/vector/iterator_access.cpp, iterator_access::possible_npe, 4, NULL_DEREFERENCE, [start of procedure iterator_access::possible_npe(),Skipped call: function or method not found,Condition is true,Condition is true,Condition is true] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, derefFirstArg2_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg2_null_deref()] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, derefFirstArg3_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg3_null_deref(),start of procedure derefFirstArg3()] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, derefFirstArg_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg_null_deref()] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, getPtr_null_deref1, 3, NULL_DEREFERENCE, [start of procedure getPtr_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, getPtr_null_deref2, 3, NULL_DEREFERENCE, [start of procedure getPtr_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, getRef_null_deref1, 3, NULL_DEREFERENCE, [start of procedure getRef_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, getRef_null_deref2, 3, NULL_DEREFERENCE, [start of procedure getRef_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, operator_star_null_deref1, 3, NULL_DEREFERENCE, [start of procedure operator_star_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, operator_star_null_deref2, 3, NULL_DEREFERENCE, [start of procedure operator_star_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] -codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp, operator_star_ok_deref, 4, UNINITIALIZED_VALUE, [start of procedure operator_star_ok_deref(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, derefFirstArg2_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg2_null_deref()] +codetoanalyze/cpp/shared/attributes/annotate.cpp, derefFirstArg3_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg3_null_deref(),start of procedure derefFirstArg3()] +codetoanalyze/cpp/shared/attributes/annotate.cpp, derefFirstArg_null_deref, 2, NULL_DEREFERENCE, [start of procedure derefFirstArg_null_deref()] +codetoanalyze/cpp/shared/attributes/annotate.cpp, getPtr_null_deref1, 3, NULL_DEREFERENCE, [start of procedure getPtr_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, getPtr_null_deref2, 3, NULL_DEREFERENCE, [start of procedure getPtr_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, getRef_null_deref1, 3, NULL_DEREFERENCE, [start of procedure getRef_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, getRef_null_deref2, 3, NULL_DEREFERENCE, [start of procedure getRef_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, operator_star_null_deref1, 3, NULL_DEREFERENCE, [start of procedure operator_star_null_deref1(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, operator_star_null_deref2, 3, NULL_DEREFERENCE, [start of procedure operator_star_null_deref2(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] +codetoanalyze/cpp/shared/attributes/annotate.cpp, operator_star_ok_deref, 4, UNINITIALIZED_VALUE, [start of procedure operator_star_ok_deref(),start of procedure TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr,return from a call to TranslateAsPtr_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr_setPtr] codetoanalyze/cpp/shared/conditional/lvalue_conditional.cpp, div0_assign_conditional, 0, DIVIDE_BY_ZERO, [start of procedure div0_assign_conditional(),start of procedure assign_conditional(),Condition is false,return from a call to assign_conditional] codetoanalyze/cpp/shared/conditional/lvalue_conditional.cpp, div0_choose_lvalue, 0, DIVIDE_BY_ZERO, [start of procedure div0_choose_lvalue(),start of procedure choose_lvalue(),Condition is true,return from a call to choose_lvalue] codetoanalyze/cpp/shared/conditional/lvalue_conditional.cpp, div0_choose_rvalue, 0, DIVIDE_BY_ZERO, [start of procedure div0_choose_rvalue(),start of procedure choose_rvalue(),Condition is true,return from a call to choose_rvalue] diff --git a/infer/tests/codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp b/infer/tests/codetoanalyze/cpp/shared/attributes/annotate.cpp similarity index 91% rename from infer/tests/codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp rename to infer/tests/codetoanalyze/cpp/shared/attributes/annotate.cpp index 973fd5c7f..645438975 100644 --- a/infer/tests/codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp +++ b/infer/tests/codetoanalyze/cpp/shared/attributes/annotate.cpp @@ -13,22 +13,22 @@ // compilation problem #include -/* Test for passing function attributes to infer via __deprecated__ attribute */ +/* Test for passing function attributes to infer via annotate attribute */ // basic test of C function with __infer_replace_with_deref_first_arg attribute int derefFirstArg(int* a, int* b) INFER_MODEL_AS_DEREF_FIRST_ARG; -// test directly with deprecated attribute +// test directly with annotate attribute int derefFirstArg2(int* a, int* b) - __attribute__((deprecated("__infer_replace_with_deref_first_arg"))) { + __attribute__((annotate("__infer_replace_with_deref_first_arg"))) { /* equivalent in real code: return *a; */ return *b; // body is in conflict with the attribute, attribute semantics // should be used } -// test with wrong deprecated attribute -int derefFirstArg3(int* a, int* b) __attribute__((deprecated("__infer_typo"))) { +// test with wrong annotate attribute +int derefFirstArg3(int* a, int* b) __attribute__((annotate("__infer_typo"))) { /* equivalent in real code: */ return *b; // there isn't any known attribute with this name, use semantics // from the body diff --git a/infer/tests/codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp.dot b/infer/tests/codetoanalyze/cpp/shared/attributes/annotate.cpp.dot similarity index 100% rename from infer/tests/codetoanalyze/cpp/shared/attributes/deprecated_hack.cpp.dot rename to infer/tests/codetoanalyze/cpp/shared/attributes/annotate.cpp.dot