Skip to content

Commit d8c79eb

Browse files
skchofacebook-github-bot
authored andcommitted
[infer] Revise empty method name for cxx constructor
Summary: For some constructors of non-class objects in C++, the clang frontend gives empty method name, e.g. struct, lambda, and union. For better readability, this diff replaces them to a constant non-empty name `__cxx_constructor`. Reviewed By: ezgicicek Differential Revision: D32558068 fbshipit-source-id: 6cc606346f
1 parent 03d3e0e commit d8c79eb

File tree

10 files changed

+176
-160
lines changed

10 files changed

+176
-160
lines changed

infer/src/clang/CType_decl.ml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,30 @@ and procname_from_decl ?tenv ?block_return_type ?outer_proc meth_decl =
673673
| None ->
674674
[]
675675
in
676+
let mk_cpp_method decl_info name_info fdi mdi =
677+
let mangled = get_mangled_method_name fdi mdi in
678+
let method_name = CAst_utils.get_unqualified_name name_info in
679+
let class_typename = get_class_typename ?tenv decl_info in
680+
mk_cpp_method ?tenv class_typename method_name ~meth_decl mangled parameters
681+
in
676682
match meth_decl with
677683
| FunctionDecl (decl_info, name_info, _, fdi) ->
678684
let name = CAst_utils.get_qualified_name name_info in
679685
mk_c_function ?tenv name (Some (decl_info, fdi)) parameters
686+
| CXXConstructorDecl (decl_info, {ni_name= ""; ni_qual_name= "" :: qual_names}, _, fdi, mdi) ->
687+
(* For some constructors of non-class objects in C++, the clang frontend gives empty method
688+
name, e.g. struct, lambda, and union. For better readability, we replace them to a
689+
constant non-empty name. *)
690+
let name_info =
691+
{ ni_name= CFrontend_config.cxx_constructor
692+
; ni_qual_name= CFrontend_config.cxx_constructor :: qual_names }
693+
in
694+
mk_cpp_method decl_info name_info fdi mdi
680695
| CXXMethodDecl (decl_info, name_info, _, fdi, mdi)
681696
| CXXConstructorDecl (decl_info, name_info, _, fdi, mdi)
682697
| CXXConversionDecl (decl_info, name_info, _, fdi, mdi)
683698
| CXXDestructorDecl (decl_info, name_info, _, fdi, mdi) ->
684-
let mangled = get_mangled_method_name fdi mdi in
685-
let method_name = CAst_utils.get_unqualified_name name_info in
686-
let class_typename = get_class_typename ?tenv decl_info in
687-
mk_cpp_method ?tenv class_typename method_name ~meth_decl mangled parameters
699+
mk_cpp_method decl_info name_info fdi mdi
688700
| ObjCMethodDecl (decl_info, name_info, mdi) ->
689701
objc_method_procname ?tenv decl_info name_info.Clang_ast_t.ni_name mdi parameters
690702
| BlockDecl _ ->

infer/src/clang/cFrontend_config.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ let clang_bin xx =
6262

6363
let class_method = "class"
6464

65+
let cxx_constructor = "__cxx_constructor"
66+
6567
let fbAssertWithSignalAndLogFunctionHelper = "FBAssertWithSignalAndLogFunctionHelper"
6668

6769
let google_LogMessageFatal = "google::LogMessageFatal_LogMessageFatal"

infer/src/clang/cFrontend_config.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ val clang_bin : string -> string
5858

5959
val class_method : string
6060

61+
val cxx_constructor : string
62+
6163
val fbAssertWithSignalAndLogFunctionHelper : string
6264

6365
val google_LogMessageFatal : string

infer/tests/codetoanalyze/cpp/biabduction/issues.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ codetoanalyze/cpp/shared/constructors/temp_object.cpp, temp_object::temp_field2_
199199
codetoanalyze/cpp/shared/constructors/temp_object.cpp, temp_object::temp_field_div0, 0, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure temp_object::temp_field_div0(),start of procedure X,return from a call to temp_object::X::X,start of procedure temp_object::div()]
200200
codetoanalyze/cpp/shared/constructors/temp_object.cpp, temp_object::temp_method_div0, 0, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure temp_object::temp_method_div0(),start of procedure X,return from a call to temp_object::X::X,start of procedure div]
201201
codetoanalyze/cpp/shared/exceptions/Exceptions.cpp, call_deref_with_null, 0, NULL_DEREFERENCE, B1, ERROR, [start of procedure call_deref_with_null(),start of procedure deref_null()]
202-
codetoanalyze/cpp/shared/lambda/lambda1.cpp, bar, 5, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure bar(),start of procedure ,return from a call to bar::lambda_shared_lambda_lambda1.cpp:9:15::,start of procedure operator(),return from a call to bar::lambda_shared_lambda_lambda1.cpp:9:15::operator()]
203-
codetoanalyze/cpp/shared/lambda/lambda1.cpp, foo, 3, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure foo(),start of procedure ,return from a call to foo::lambda_shared_lambda_lambda1.cpp:17:17::,start of procedure ,return from a call to foo::lambda_shared_lambda_lambda1.cpp:18:12::,start of procedure operator(),return from a call to foo::lambda_shared_lambda_lambda1.cpp:18:12::operator()]
202+
codetoanalyze/cpp/shared/lambda/lambda1.cpp, bar, 5, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure bar(),start of procedure __cxx_constructor,return from a call to bar::lambda_shared_lambda_lambda1.cpp:9:15::__cxx_constructor,start of procedure operator(),return from a call to bar::lambda_shared_lambda_lambda1.cpp:9:15::operator()]
203+
codetoanalyze/cpp/shared/lambda/lambda1.cpp, foo, 3, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure foo(),start of procedure __cxx_constructor,return from a call to foo::lambda_shared_lambda_lambda1.cpp:17:17::__cxx_constructor,start of procedure __cxx_constructor,return from a call to foo::lambda_shared_lambda_lambda1.cpp:18:12::__cxx_constructor,start of procedure operator(),return from a call to foo::lambda_shared_lambda_lambda1.cpp:18:12::operator()]
204204
codetoanalyze/cpp/shared/lambda/lambda1.cpp, foo::lambda_shared_lambda_lambda1.cpp:17:17::operator(), 0, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure operator()]
205205
codetoanalyze/cpp/shared/methods/conversion_operator.cpp, conversion_operator::branch_div0, 4, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure conversion_operator::branch_div0(),start of procedure X,return from a call to conversion_operator::X::X,start of procedure operator_bool,return from a call to conversion_operator::X::operator_bool,Taking true branch,start of procedure operator_int,return from a call to conversion_operator::X::operator_int]
206206
codetoanalyze/cpp/shared/methods/conversion_operator.cpp, conversion_operator::y_branch_div0, 6, DIVIDE_BY_ZERO, no_bucket, ERROR, [start of procedure conversion_operator::y_branch_div0(),start of procedure Y,return from a call to conversion_operator::Y::Y,start of procedure operator_X,start of procedure X,return from a call to conversion_operator::X::X,start of procedure X,return from a call to conversion_operator::X::X,return from a call to conversion_operator::Y::operator_X,start of procedure X,return from a call to conversion_operator::X::X,start of procedure operator_bool,return from a call to conversion_operator::X::operator_bool,Taking true branch,start of procedure operator_X,start of procedure X,return from a call to conversion_operator::X::X,start of procedure X,return from a call to conversion_operator::X::X,return from a call to conversion_operator::Y::operator_X,start of procedure X,return from a call to conversion_operator::X::X,start of procedure operator_int,return from a call to conversion_operator::X::operator_int]

infer/tests/codetoanalyze/cpp/frontend/nestedoperators/union.cpp.dot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ digraph cfg {
77
"__infer_globals_initializer_y.0ea250be2dd991733c9131c53abc3c54_2" [label="2: Exit __infer_globals_initializer_y \n " color=yellow style=filled]
88

99

10-
"__infer_globals_initializer_y.0ea250be2dd991733c9131c53abc3c54_3" [label="3: DeclStmt \n VARIABLE_DECLARED(#GB<codetoanalyze/cpp/frontend/nestedoperators/union.cpp>$y:anonymous_union_nestedoperators_union.cpp:13:1); [line 13, column 1]\n n$0=_fun_anonymous_union_nestedoperators_union.cpp:13:1::(&#GB<codetoanalyze/cpp/frontend/nestedoperators/union.cpp>$y:anonymous_union_nestedoperators_union.cpp:13:1*) [line 23, column 3]\n " shape="box"]
10+
"__infer_globals_initializer_y.0ea250be2dd991733c9131c53abc3c54_3" [label="3: DeclStmt \n VARIABLE_DECLARED(#GB<codetoanalyze/cpp/frontend/nestedoperators/union.cpp>$y:anonymous_union_nestedoperators_union.cpp:13:1); [line 13, column 1]\n n$0=_fun_anonymous_union_nestedoperators_union.cpp:13:1::__cxx_constructor(&#GB<codetoanalyze/cpp/frontend/nestedoperators/union.cpp>$y:anonymous_union_nestedoperators_union.cpp:13:1*) [line 23, column 3]\n " shape="box"]
1111

1212

1313
"__infer_globals_initializer_y.0ea250be2dd991733c9131c53abc3c54_3" -> "__infer_globals_initializer_y.0ea250be2dd991733c9131c53abc3c54_2" ;
@@ -38,11 +38,11 @@ digraph cfg {
3838

3939

4040
"main.fad58de7366495db4650cfefac2fcd61_7" -> "main.fad58de7366495db4650cfefac2fcd61_6" ;
41-
"#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.b2a6fc5036a060aa9fbc38e79d264a62_1" [label="1: Start anonymous_union_nestedoperators_union.cpp:13:1::\nFormals: this:anonymous_union_nestedoperators_union.cpp:13:1*\nLocals: \n " color=yellow style=filled]
41+
"__cxx_constructor#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.dc90875270147ed05fe2b6c5c9de5f66_1" [label="1: Start anonymous_union_nestedoperators_union.cpp:13:1::__cxx_constructor\nFormals: this:anonymous_union_nestedoperators_union.cpp:13:1*\nLocals: \n " color=yellow style=filled]
4242

4343

44-
"#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.b2a6fc5036a060aa9fbc38e79d264a62_1" -> "#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.b2a6fc5036a060aa9fbc38e79d264a62_2" ;
45-
"#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.b2a6fc5036a060aa9fbc38e79d264a62_2" [label="2: Exit anonymous_union_nestedoperators_union.cpp:13:1:: \n " color=yellow style=filled]
44+
"__cxx_constructor#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.dc90875270147ed05fe2b6c5c9de5f66_1" -> "__cxx_constructor#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.dc90875270147ed05fe2b6c5c9de5f66_2" ;
45+
"__cxx_constructor#anonymous_union_nestedoperators_union.cpp:13:1#{}12006367870009433944.dc90875270147ed05fe2b6c5c9de5f66_2" [label="2: Exit anonymous_union_nestedoperators_union.cpp:13:1::__cxx_constructor \n " color=yellow style=filled]
4646

4747

4848
}

infer/tests/codetoanalyze/cpp/performance-11/cost-issues.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ codetoanalyze/cpp/performance/deque.cpp, iteratec_over_deque_linear, 4 + 2 ⋅ d
2121
codetoanalyze/cpp/performance/deque.cpp, range_based_loop_over_deque_linear, 9 + 5 ⋅ d->elements.length.ub + 14 ⋅ (d->elements.length.ub + 1), OnUIThread:false, [{d->elements.length.ub + 1},Loop,{d->elements.length.ub},Loop]
2222
codetoanalyze/cpp/performance/foreachtest.cpp, add, 3, OnUIThread:false, []
2323
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN, 21, OnUIThread:false, []
24-
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_.._performance_foreachtest.cpp:39:42::, 3, OnUIThread:false, []
24+
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_.._performance_foreachtest.cpp:39:42::__cxx_constructor, 3, OnUIThread:false, []
2525
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_.._performance_foreachtest.cpp:39:42::__infer_inner_destructor_~, 2, OnUIThread:false, []
2626
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_.._performance_foreachtest.cpp:39:42::operator(), 28, OnUIThread:false, []
2727
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_.._performance_foreachtest.cpp:39:42::~, 3, OnUIThread:false, []
2828
codetoanalyze/cpp/performance/foreachtest.cpp, loop_linear_list, 12 + 8 ⋅ list->elements.length.ub + 14 ⋅ (list->elements.length.ub + 1), OnUIThread:false, [{list->elements.length.ub + 1},Loop,{list->elements.length.ub},Loop]
2929
codetoanalyze/cpp/performance/foreachtest.cpp, loop_linear_vec, 18 + 14 ⋅ vec->cpp.vector_elem.length.ub + 18 ⋅ (vec->cpp.vector_elem.length.ub + 1), OnUIThread:false, [{vec->cpp.vector_elem.length.ub + 1},Loop,{vec->cpp.vector_elem.length.ub},Loop]
3030
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN, 9, OnUIThread:false, []
31-
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_.._performance_foreachtest.cpp:31:36::, 0, OnUIThread:false, []
31+
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_.._performance_foreachtest.cpp:31:36::__cxx_constructor, 0, OnUIThread:false, []
3232
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_.._performance_foreachtest.cpp:31:36::operator(), 7, OnUIThread:false, []
3333
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN, 27, OnUIThread:false, []
34-
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_.._performance_foreachtest.cpp:45:36::, 3, OnUIThread:false, []
34+
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_.._performance_foreachtest.cpp:45:36::__cxx_constructor, 3, OnUIThread:false, []
3535
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_.._performance_foreachtest.cpp:45:36::__infer_inner_destructor_~, 2, OnUIThread:false, []
3636
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_.._performance_foreachtest.cpp:45:36::operator(), 38, OnUIThread:false, []
3737
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_.._performance_foreachtest.cpp:45:36::~, 3, OnUIThread:false, []

infer/tests/codetoanalyze/cpp/performance/cost-issues.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ codetoanalyze/cpp/performance/deque.cpp, iteratec_over_deque_linear, 3 + 2 ⋅ d
2121
codetoanalyze/cpp/performance/deque.cpp, range_based_loop_over_deque_linear, 7 + 5 ⋅ d->elements.length.ub + 14 ⋅ (d->elements.length.ub + 1), OnUIThread:false, [{d->elements.length.ub + 1},Loop,{d->elements.length.ub},Loop]
2222
codetoanalyze/cpp/performance/foreachtest.cpp, add, 3, OnUIThread:false, []
2323
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN, 13, OnUIThread:false, []
24-
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_foreachtest.cpp:39:42::, 3, OnUIThread:false, []
24+
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_foreachtest.cpp:39:42::__cxx_constructor, 3, OnUIThread:false, []
2525
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_foreachtest.cpp:39:42::__infer_inner_destructor_~, 2, OnUIThread:false, []
2626
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_foreachtest.cpp:39:42::operator(), 26, OnUIThread:false, []
2727
codetoanalyze/cpp/performance/foreachtest.cpp, list_quadratic_FN::lambda_foreachtest.cpp:39:42::~, 3, OnUIThread:false, []
2828
codetoanalyze/cpp/performance/foreachtest.cpp, loop_linear_list, 10 + 8 ⋅ list->elements.length.ub + 14 ⋅ (list->elements.length.ub + 1), OnUIThread:false, [{list->elements.length.ub + 1},Loop,{list->elements.length.ub},Loop]
2929
codetoanalyze/cpp/performance/foreachtest.cpp, loop_linear_vec, 10 + 14 ⋅ vec->cpp.vector_elem.length.ub + 18 ⋅ (vec->cpp.vector_elem.length.ub + 1), OnUIThread:false, [{vec->cpp.vector_elem.length.ub + 1},Loop,{vec->cpp.vector_elem.length.ub},Loop]
3030
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN, 5, OnUIThread:false, []
31-
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_foreachtest.cpp:31:36::, 0, OnUIThread:false, []
31+
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_foreachtest.cpp:31:36::__cxx_constructor, 0, OnUIThread:false, []
3232
codetoanalyze/cpp/performance/foreachtest.cpp, map_linear_FN::lambda_foreachtest.cpp:31:36::operator(), 7, OnUIThread:false, []
3333
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN, 13, OnUIThread:false, []
34-
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_foreachtest.cpp:45:36::, 3, OnUIThread:false, []
34+
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_foreachtest.cpp:45:36::__cxx_constructor, 3, OnUIThread:false, []
3535
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_foreachtest.cpp:45:36::__infer_inner_destructor_~, 2, OnUIThread:false, []
3636
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_foreachtest.cpp:45:36::operator(), 30, OnUIThread:false, []
3737
codetoanalyze/cpp/performance/foreachtest.cpp, vector_quadratic_FN::lambda_foreachtest.cpp:45:36::~, 3, OnUIThread:false, []

0 commit comments

Comments
 (0)