[infer] Add integral constant expression info

Summary:
In order to know whether a global variable is an integral constant
expression in C, this diff adds a field for the results of isInitICE.

The controller you requested could not be found.: facebook-clang-plugins

Reviewed By: mbouaziz

Differential Revision: D12838521

fbshipit-source-id: 388bff1f3
master
Sungkeun Cho 6 years ago committed by Facebook Github Bot
parent f0fd0fd7ac
commit e5ee023aa3

@ -1 +1 @@
Subproject commit 45a30fed67fb7b7697aacace1d93f17655105c54 Subproject commit bf80f91312d92617eebddb8331f971682acdb9ee

@ -25,6 +25,7 @@ type pvar_kind =
| Global_var of | Global_var of
{ translation_unit: translation_unit { translation_unit: translation_unit
; is_constexpr: bool (* is it compile constant? *) ; is_constexpr: bool (* is it compile constant? *)
; is_ice: bool (* is it integral constant expression? *)
; is_pod: bool ; is_pod: bool
; is_static_local: bool ; is_static_local: bool
; is_static_global: bool } (** global variable *) ; is_static_global: bool } (** global variable *)
@ -77,9 +78,10 @@ let pp_ f pv =
F.fprintf f "%a|abducedRetvar" Mangled.pp name F.fprintf f "%a|abducedRetvar" Mangled.pp name
| Abduced_ref_param (_, index, _) -> | Abduced_ref_param (_, index, _) ->
F.fprintf f "%a|abducedRefParam%d" Mangled.pp name index F.fprintf f "%a|abducedRefParam%d" Mangled.pp name index
| Global_var {translation_unit; is_constexpr; is_pod} -> | Global_var {translation_unit; is_constexpr; is_ice; is_pod} ->
F.fprintf f "#GB<%a%s%s>$%a" pp_translation_unit translation_unit F.fprintf f "#GB<%a%s%s%s>$%a" pp_translation_unit translation_unit
(if is_constexpr then "|const" else "") (if is_constexpr then "|const" else "")
(if is_ice then "|ice" else "")
(if not is_pod then "|!pod" else "") (if not is_pod then "|!pod" else "")
Mangled.pp name Mangled.pp name
| Seed_var -> | Seed_var ->
@ -215,11 +217,12 @@ let mk_callee (name : Mangled.t) (proc_name : Typ.Procname.t) : t =
(** create a global variable with the given name *) (** create a global variable with the given name *)
let mk_global ?(is_constexpr = false) ?(is_pod = true) ?(is_static_local = false) let mk_global ?(is_constexpr = false) ?(is_ice = false) ?(is_pod = true) ?(is_static_local = false)
?(is_static_global = false) ?translation_unit (name : Mangled.t) : t = ?(is_static_global = false) ?translation_unit (name : Mangled.t) : t =
{ pv_hash= name_hash name { pv_hash= name_hash name
; pv_name= name ; pv_name= name
; pv_kind= Global_var {translation_unit; is_constexpr; is_pod; is_static_local; is_static_global} ; pv_kind=
Global_var {translation_unit; is_constexpr; is_ice; is_pod; is_static_local; is_static_global}
} }

@ -94,6 +94,7 @@ val mk_callee : Mangled.t -> Typ.Procname.t -> t
val mk_global : val mk_global :
?is_constexpr:bool ?is_constexpr:bool
-> ?is_ice:bool
-> ?is_pod:bool -> ?is_pod:bool
-> ?is_static_local:bool -> ?is_static_local:bool
-> ?is_static_global:bool -> ?is_static_global:bool

@ -121,6 +121,7 @@ let mk_sil_global_var {CFrontend_config.source_file} ?(mk_name = fun _ x -> x) d
Some source_file Some source_file
in in
let is_constexpr = var_decl_info.Clang_ast_t.vdi_is_const_expr in let is_constexpr = var_decl_info.Clang_ast_t.vdi_is_const_expr in
let is_ice = var_decl_info.Clang_ast_t.vdi_is_init_ice in
let is_pod = let is_pod =
CAst_utils.get_desugared_type qt.Clang_ast_t.qt_type_ptr CAst_utils.get_desugared_type qt.Clang_ast_t.qt_type_ptr
|> Option.bind ~f:(function |> Option.bind ~f:(function
@ -142,7 +143,7 @@ let mk_sil_global_var {CFrontend_config.source_file} ?(mk_name = fun _ x -> x) d
&& (not var_decl_info.Clang_ast_t.vdi_is_static_data_member) && (not var_decl_info.Clang_ast_t.vdi_is_static_data_member)
&& match var_decl_info.Clang_ast_t.vdi_storage_class with Some "static" -> true | _ -> false && match var_decl_info.Clang_ast_t.vdi_storage_class with Some "static" -> true | _ -> false
in in
Pvar.mk_global ~is_constexpr ~is_pod Pvar.mk_global ~is_constexpr ~is_ice ~is_pod
~is_static_local:var_decl_info.Clang_ast_t.vdi_is_static_local ~is_static_global ~is_static_local:var_decl_info.Clang_ast_t.vdi_is_static_local ~is_static_global
?translation_unit (mk_name name_string simple_name) ?translation_unit (mk_name name_string simple_name)

@ -18,7 +18,7 @@ digraph cfg {
"__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_2" [label="2: Exit __infer_globals_initializer_v \n " color=yellow style=filled] "__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_2" [label="2: Exit __infer_globals_initializer_v \n " color=yellow style=filled]
"__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp>$v:int=2 [line 15, column 1]\n " shape="box"] "__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp|ice>$v:int=2 [line 15, column 1]\n " shape="box"]
"__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_3" -> "__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_2" ; "__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_3" -> "__infer_globals_initializer_v#708fabe5dc8ff523caaa5f44184921e8.588095fa475e4a9e8c83f50f26a48ea9_2" ;
@ -40,11 +40,11 @@ digraph cfg {
"test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_2" [label="2: Exit test2 \n " color=yellow style=filled] "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_2" [label="2: Exit test2 \n " color=yellow style=filled]
"test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp>$v:int [line 19, column 10]\n *&return:int=n$0 [line 19, column 3]\n " shape="box"] "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp|ice>$v:int [line 19, column 10]\n *&return:int=n$0 [line 19, column 3]\n " shape="box"]
"test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" -> "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_2" ; "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" -> "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_2" ;
"test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_4" [label="4: DeclStmt \n n$2=*&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp>$v:int [line 18, column 15]\n *&local:int=n$2 [line 18, column 3]\n " shape="box"] "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_4" [label="4: DeclStmt \n n$2=*&#GB<codetoanalyze/cpp/frontend/globals/global_const1.cpp|ice>$v:int [line 18, column 15]\n *&local:int=n$2 [line 18, column 3]\n " shape="box"]
"test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_4" -> "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" ; "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_4" -> "test2#3587805488049044947.69e45cfdc4e36a6f741ce3985858724b_3" ;

@ -28,7 +28,7 @@ digraph cfg {
"__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_7" -> "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_3" ; "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_7" -> "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_3" ;
"__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_8" [label="8: DeclStmt \n n$1=*&0$?%__sil_tmpSIL_temp_conditional___n$0:int [line 8, column 20]\n *&#GB<codetoanalyze/cpp/frontend/globals/global_const2.cpp>$global:int=n$1 [line 8, column 1]\n " shape="box"] "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_8" [label="8: DeclStmt \n n$1=*&0$?%__sil_tmpSIL_temp_conditional___n$0:int [line 8, column 20]\n *&#GB<codetoanalyze/cpp/frontend/globals/global_const2.cpp|ice>$global:int=n$1 [line 8, column 1]\n " shape="box"]
"__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_8" -> "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_2" ; "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_8" -> "__infer_globals_initializer_global.bdc08c089842ce08b974b22a75daf78e_2" ;
@ -39,7 +39,7 @@ digraph cfg {
"test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_2" [label="2: Exit test \n " color=yellow style=filled] "test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_2" [label="2: Exit test \n " color=yellow style=filled]
"test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/frontend/globals/global_const2.cpp>$global:int [line 9, column 21]\n *&return:int=n$0 [line 9, column 14]\n " shape="box"] "test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/frontend/globals/global_const2.cpp|ice>$global:int [line 9, column 21]\n *&return:int=n$0 [line 9, column 14]\n " shape="box"]
"test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_3" -> "test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_2" ; "test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_3" -> "test#18241244337164948030.afc14f193ad97442f67ac7183be789bc_2" ;

@ -51,7 +51,7 @@ digraph cfg {
"dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_2" [label="2: Exit __infer_globals_initializer_pass_by_val::dummy_struct \n " color=yellow style=filled] "dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_2" [label="2: Exit __infer_globals_initializer_pass_by_val::dummy_struct \n " color=yellow style=filled]
"dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/shared/methods/byvals.cpp>$pass_by_val::dummy_struct.x:int=0 [line 15, column 25]\n *&#GB<codetoanalyze/cpp/shared/methods/byvals.cpp>$pass_by_val::dummy_struct.y:int*=null [line 15, column 25]\n " shape="box"] "dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/shared/methods/byvals.cpp|ice>$pass_by_val::dummy_struct.x:int=0 [line 15, column 25]\n *&#GB<codetoanalyze/cpp/shared/methods/byvals.cpp|ice>$pass_by_val::dummy_struct.y:int*=null [line 15, column 25]\n " shape="box"]
"dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_3" -> "dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_2" ; "dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_3" -> "dummy_struct#__infer_globals_initializer_pass_by_val.24fe54080733cebf362d2b34e691bb44_2" ;

@ -11,7 +11,7 @@ digraph cfg {
"main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ; "main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ;
"main.fad58de7366495db4650cfefac2fcd61_4" [label="4: BinaryOperatorStmt: Assign \n n$1=*&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp>$bar::pi:double [line 55, column 7]\n *&j:double=n$1 [line 55, column 3]\n " shape="box"] "main.fad58de7366495db4650cfefac2fcd61_4" [label="4: BinaryOperatorStmt: Assign \n n$1=*&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp|ice>$bar::pi:double [line 55, column 7]\n *&j:double=n$1 [line 55, column 3]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_4" -> "main.fad58de7366495db4650cfefac2fcd61_3" ; "main.fad58de7366495db4650cfefac2fcd61_4" -> "main.fad58de7366495db4650cfefac2fcd61_3" ;
@ -54,7 +54,7 @@ digraph cfg {
"pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_2" [label="2: Exit __infer_globals_initializer_bar::pi \n " color=yellow style=filled] "pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_2" [label="2: Exit __infer_globals_initializer_bar::pi \n " color=yellow style=filled]
"pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp>$bar::pi:double=3.1416 [line 27, column 1]\n " shape="box"] "pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp|ice>$bar::pi:double=3.1416 [line 27, column 1]\n " shape="box"]
"pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_3" -> "pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_2" ; "pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_3" -> "pi#__infer_globals_initializer_bar.1155d696836634e07d40a8f71831e209_2" ;
@ -76,7 +76,7 @@ digraph cfg {
"value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_2" [label="2: Exit bar::value \n " color=yellow style=filled] "value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_2" [label="2: Exit bar::value \n " color=yellow style=filled]
"value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp>$bar::pi:double [line 28, column 29]\n *&return:double=(2 * n$0) [line 28, column 18]\n " shape="box"] "value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_3" [label="3: Return Stmt \n n$0=*&#GB<codetoanalyze/cpp/shared/namespace/namespace.cpp|ice>$bar::pi:double [line 28, column 29]\n *&return:double=(2 * n$0) [line 28, column 18]\n " shape="box"]
"value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_3" -> "value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_2" ; "value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_3" -> "value#bar#16302148298864778751.e55afab5e7523c08687d7e6558d5dad5_2" ;

@ -7,7 +7,7 @@ digraph cfg {
"__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_2" [label="2: Exit __infer_globals_initializer___someFields \n " color=yellow style=filled] "__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_2" [label="2: Exit __infer_globals_initializer___someFields \n " color=yellow style=filled]
"__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm>$__someFields.field1:float=1 [line 14, column 36]\n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm>$__someFields.field2:float=2 [line 14, column 36]\n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm>$__someFields.field3:float=3 [line 14, column 36]\n " shape="box"] "__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_3" [label="3: DeclStmt \n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm|ice>$__someFields.field1:float=1 [line 14, column 36]\n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm|ice>$__someFields.field2:float=2 [line 14, column 36]\n *&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm|ice>$__someFields.field3:float=3 [line 14, column 36]\n " shape="box"]
"__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_3" -> "__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_2" ; "__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_3" -> "__infer_globals_initializer___someFields#305cac08d8197bd145f7f55cc8a06d16.794b83eea8b5794c71808060b1f3b5c7_2" ;
@ -18,7 +18,7 @@ digraph cfg {
"fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_2" [label="2: Exit fields \n " color=yellow style=filled] "fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_2" [label="2: Exit fields \n " color=yellow style=filled]
"fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_3" [label="3: Return Stmt \n n$0=*&__return_param:Fields* [line 20, column 19]\n n$1=_fun_Fields_(n$0:Fields*,&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm>$__someFields:Fields const &) [line 20, column 26]\n " shape="box"] "fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_3" [label="3: Return Stmt \n n$0=*&__return_param:Fields* [line 20, column 19]\n n$1=_fun_Fields_(n$0:Fields*,&#GB<codetoanalyze/objcpp/frontend/global_const/global_const.mm|ice>$__someFields:Fields const &) [line 20, column 26]\n " shape="box"]
"fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_3" -> "fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_2" ; "fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_3" -> "fields(class Fields)#3037629886785813687.ade89225d198ce505301d5cdffda48f1_2" ;

Loading…
Cancel
Save