[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
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent cccefd6434
commit 21af28619f

@ -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"))) {}

@ -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)

@ -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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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<int>_setPtr,return from a call to TranslateAsPtr<int>_TranslateAsPtr,start of procedure setPtr,return from a call to TranslateAsPtr<int>_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]

@ -13,22 +13,22 @@
// compilation problem
#include <infer/models/cpp/include/infer_model/infer_traits.h>
/* 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
Loading…
Cancel
Save