Skip to content

Commit

Permalink
[clang] Translating the constructor attribute
Browse files Browse the repository at this point in the history
Summary: Needed in the following diff to add a checker for calling dispatch-once from static constructors.

Reviewed By: ngorogiannis

Differential Revision: D65488735

fbshipit-source-id: a471958d33a410b4a0a268aa834f0f530a2d57b5
  • Loading branch information
dulmarod authored and facebook-github-bot committed Nov 8, 2024
1 parent 5db9da5 commit 3a86ac0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions infer/src/IR/ProcAttributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type t =
; is_cpp_copy_assignment: bool (** true if the procedure is a copy assignment *)
; is_cpp_copy_ctor: bool (** true if the procedure is a copy constructor *)
; is_cpp_move_ctor: bool (** true if the procedure is a move constructor *)
; is_static_ctor: bool (** true if the procedure has the constructor attribute *)
; is_cpp_deleted: bool (** true if the procedure is deleted *)
; is_cpp_implicit: bool
(** returns false if the declaration exists in code and true if it was created implicitly by
Expand Down Expand Up @@ -203,6 +204,7 @@ let default translation_unit proc_name =
; is_cpp_copy_assignment= false
; is_cpp_copy_ctor= false
; is_cpp_move_ctor= false
; is_static_ctor= false
; is_cpp_deleted= false
; is_cpp_implicit= false
; is_defined= false
Expand Down Expand Up @@ -282,6 +284,7 @@ let pp f
; is_cpp_copy_assignment
; is_cpp_copy_ctor
; is_cpp_move_ctor
; is_static_ctor
; is_cpp_deleted
; is_cpp_implicit
; is_defined
Expand Down Expand Up @@ -347,6 +350,7 @@ let pp f
is_cpp_copy_assignment f () ;
pp_bool_default ~default:default.is_cpp_copy_ctor "is_cpp_copy_ctor" is_cpp_copy_ctor f () ;
pp_bool_default ~default:default.is_cpp_move_ctor "is_cpp_move_ctor" is_cpp_move_ctor f () ;
pp_bool_default ~default:default.is_static_ctor "is_static_ctor" is_static_ctor f () ;
pp_bool_default ~default:default.is_cpp_deleted "is_deleted" is_cpp_deleted f () ;
pp_bool_default ~default:default.is_cpp_implicit "is_cpp_implicit" is_cpp_implicit f () ;
pp_bool_default ~default:default.is_defined "is_defined" is_defined f () ;
Expand Down
1 change: 1 addition & 0 deletions infer/src/IR/ProcAttributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type t =
; is_cpp_copy_assignment: bool (** true if the procedure is a copy assignment *)
; is_cpp_copy_ctor: bool (** true if the procedure is a copy constructor *)
; is_cpp_move_ctor: bool (** true if the procedure is a move constructor *)
; is_static_ctor: bool (** true if the procedure has the constructor attribute *)
; is_cpp_deleted: bool (** true if the procedure is deleted *)
; is_cpp_implicit: bool
(** returns false if the declaration exists in code and true if it was created implicitly by
Expand Down
11 changes: 11 additions & 0 deletions infer/src/clang/CMethodProperties.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ let is_cpp_move_ctor method_decl =
false


let is_static_ctor method_decl =
let open Clang_ast_t in
match method_decl with
| FunctionDecl (decl_info, _, _, _) ->
let attributes = decl_info.Clang_ast_t.di_attributes in
List.exists attributes ~f:(fun attr ->
match attr with `ConstructorAttr _ -> true | _ -> false )
| _ ->
false


let is_cpp_deleted method_decl =
let open Clang_ast_t in
match method_decl with
Expand Down
2 changes: 2 additions & 0 deletions infer/src/clang/CMethodProperties.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ val is_cpp_copy_ctor : Clang_ast_t.decl -> bool

val is_cpp_move_ctor : Clang_ast_t.decl -> bool

val is_static_ctor : Clang_ast_t.decl -> bool

val is_cpp_deleted : Clang_ast_t.decl -> bool

val is_constexpr : Clang_ast_t.decl -> bool
Expand Down
2 changes: 2 additions & 0 deletions infer/src/clang/CType_decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ module BuildMethodSignature = struct
let is_cpp_copy_assignment = CMethodProperties.is_cpp_copy_assignment method_decl in
let is_cpp_copy_ctor = CMethodProperties.is_cpp_copy_ctor method_decl in
let is_cpp_move_ctor = CMethodProperties.is_cpp_move_ctor method_decl in
let is_static_ctor = CMethodProperties.is_static_ctor method_decl in
let is_cpp_deleted = CMethodProperties.is_cpp_deleted method_decl in
let is_cpp_implicit = CAst_utils.is_cpp_implicit_decl method_decl in
let is_no_return = CMethodProperties.is_no_return method_decl in
Expand All @@ -206,6 +207,7 @@ module BuildMethodSignature = struct
; is_cpp_copy_assignment
; is_cpp_copy_ctor
; is_cpp_move_ctor
; is_static_ctor
; is_cpp_deleted
; is_cpp_implicit
; ret_type= (ret_type, ret_typ_annot)
Expand Down
8 changes: 5 additions & 3 deletions infer/src/clang/cMethodSignature.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type t =
; is_cpp_copy_assignment: bool
; is_cpp_copy_ctor: bool
; is_cpp_move_ctor: bool
; is_static_ctor: bool
; is_cpp_deleted: bool
; is_cpp_implicit: bool
; block_as_arg_attributes: ProcAttributes.block_as_arg_attributes option
Expand All @@ -68,9 +69,9 @@ let is_setter {pointer_to_property_opt; params} =
let mk name class_param params ret_type ?(has_added_return_param = false) ?(is_ret_type_pod = true)
~is_ret_constexpr attributes loc method_kind ?(is_cpp_const_member_fun = false)
?(is_cpp_virtual = false) ?(is_cpp_copy_assignment = false) ?(is_cpp_copy_ctor = false)
?(is_cpp_move_ctor = false) ?(is_cpp_deleted = false) ?(is_cpp_implicit = false)
?(block_as_arg_attributes = None) ?(is_no_return = false) ?(is_variadic = false)
pointer_to_parent pointer_to_property_opt return_param_typ access =
?(is_cpp_move_ctor = false) ?(is_static_ctor = false) ?(is_cpp_deleted = false)
?(is_cpp_implicit = false) ?(block_as_arg_attributes = None) ?(is_no_return = false)
?(is_variadic = false) pointer_to_parent pointer_to_property_opt return_param_typ access =
{ name
; access
; class_param
Expand All @@ -87,6 +88,7 @@ let mk name class_param params ret_type ?(has_added_return_param = false) ?(is_r
; is_cpp_copy_assignment
; is_cpp_copy_ctor
; is_cpp_move_ctor
; is_static_ctor
; is_cpp_deleted
; is_cpp_implicit
; block_as_arg_attributes
Expand Down
2 changes: 2 additions & 0 deletions infer/src/clang/cMethodSignature.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type t =
; is_cpp_copy_assignment: bool
; is_cpp_copy_ctor: bool
; is_cpp_move_ctor: bool
; is_static_ctor: bool
; is_cpp_deleted: bool
; is_cpp_implicit: bool
; block_as_arg_attributes: ProcAttributes.block_as_arg_attributes option
Expand Down Expand Up @@ -65,6 +66,7 @@ val mk :
-> ?is_cpp_copy_assignment:bool
-> ?is_cpp_copy_ctor:bool
-> ?is_cpp_move_ctor:bool
-> ?is_static_ctor:bool
-> ?is_cpp_deleted:bool
-> ?is_cpp_implicit:bool
-> ?block_as_arg_attributes:ProcAttributes.block_as_arg_attributes option
Expand Down
1 change: 1 addition & 0 deletions infer/src/clang/cMethod_trans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ let create_attributes_helper ?loc_instantiated ?(set_objc_accessor_attr = false)
; is_cpp_const_member_fun= ms.CMethodSignature.is_cpp_const_member_fun
; is_cpp_copy_ctor= ms.CMethodSignature.is_cpp_copy_ctor
; is_cpp_move_ctor= ms.CMethodSignature.is_cpp_move_ctor
; is_static_ctor= ms.CMethodSignature.is_static_ctor
; is_cpp_copy_assignment= ms.CMethodSignature.is_cpp_copy_assignment
; is_cpp_deleted= ms.CMethodSignature.is_cpp_deleted
; is_cpp_implicit= ms.CMethodSignature.is_cpp_implicit
Expand Down

0 comments on commit 3a86ac0

Please sign in to comment.