Added new predicate is_const_expr()

Reviewed By: jvillard

Differential Revision: D9496229

fbshipit-source-id: c0bccf8c9
master
Dino Distefano 6 years ago committed by Facebook Github Bot
parent 0d4007e6be
commit 21145c75c9

@ -507,6 +507,18 @@ let is_const_expr_var an =
match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false match an with Ctl_parser_types.Decl d -> CAst_utils.is_const_expr_var d | _ -> false
let is_const an =
match an with
| Ctl_parser_types.Stmt s -> (
match Clang_ast_proj.get_expr_tuple s with
| Some (_, _, ei) ->
ei.Clang_ast_t.ei_qual_type.qt_is_const
| _ ->
false )
| _ ->
false
let decl_ref_name ?kind name st = let decl_ref_name ?kind name st =
match st with match st with
| Clang_ast_t.DeclRefExpr (_, _, _, drti) -> ( | Clang_ast_t.DeclRefExpr (_, _, _, drti) -> (

@ -42,6 +42,9 @@ val is_static_local_var : Ctl_parser_types.ast_node -> bool
val is_const_expr_var : Ctl_parser_types.ast_node -> bool val is_const_expr_var : Ctl_parser_types.ast_node -> bool
(** 'is_const_expr_var an' is true iff an is a 'const' variable declaration *) (** 'is_const_expr_var an' is true iff an is a 'const' variable declaration *)
val is_const : Ctl_parser_types.ast_node -> bool
(** 'is_const an' is true iff an is a 'const' expression *)
val call_function : Ctl_parser_types.ast_node -> ALVar.alexp -> bool val call_function : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
(** 'call_function an name' is true iff an is a call to a function whose name contains 'name' *) (** 'call_function an name' is true iff an is a call to a function whose name contains 'name' *)

@ -998,6 +998,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.is_class an cname CPredicates.is_class an cname
| "is_const_var", [], an -> | "is_const_var", [], an ->
CPredicates.is_const_expr_var an CPredicates.is_const_expr_var an
| "is_const", [], an ->
CPredicates.is_const an
| "is_decl", [], an -> | "is_decl", [], an ->
CPredicates.is_decl an CPredicates.is_decl an
| "is_enum_constant", [cname], an -> | "is_enum_constant", [cname], an ->

@ -47,11 +47,17 @@ DEFINE-CHECKER ITERATOR = {
}; };
DEFINE-CHECKER CXX11_CONSTANT_EXPR = { DEFINE-CHECKER CXX11_CONSTANT_EXPR = {
LET eventually_const_sub_expr = HOLDS-NEXT WITH-TRANSITION InitExpr
(is_const HOLDS-EVENTUALLY);
LET not_static_and_not_global = NOT (is_global_var OR is_static_local_var);
SET report_when = SET report_when =
WHEN WHEN
is_init_expr_cxx11_constant() not_static_and_not_global AND (is_init_expr_cxx11_constant() OR eventually_const_sub_expr)
HOLDS-IN-NODE VarDecl; HOLDS-IN-NODE VarDecl;
SET message = "Found cxx11 constant expression"; SET message = "Found cxx11 constant expression";

@ -1,20 +1,20 @@
codetoanalyze/cpp/linters/extracopy.cpp, Linters_dummy_method, 33, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/cxxconst.cpp, test, 24, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, get_a, 21, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/cxxconst.cpp, test, 27, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, get_a_ref, 16, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/cxxconst.cpp, test, 29, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 26, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/cxxconst.cpp, test, 30, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/cxxconst.cpp, test, 31, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/cxxconst.cpp, test, 33, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 27, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_a, 27, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 27, EXTRA_COPY, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_a, 27, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 28, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_a, 28, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 29, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_const_exp, 53, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_const_exp, 54, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_const_exp, 55, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 36, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_map, 36, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 37, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_map, 37, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 37, EXTRA_COPY, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_map, 37, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 40, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_map, 40, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 43, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/extracopy.cpp, test_map, 43, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 10, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 11, ITERATOR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/iter.cpp, test, 11, ITERATOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 12, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 12, EXTRA_COPY, no_bucket, WARNING, [] codetoanalyze/cpp/linters/iter.cpp, test, 12, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 12, ITERATOR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/iter.cpp, test, 12, ITERATOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/type_namespace.cpp, test, 11, CXX11_CONSTANT_EXPR, no_bucket, WARNING, [] codetoanalyze/cpp/linters/type_namespace.cpp, test, 11, CXX11_CONSTANT_EXPR, no_bucket, WARNING, []

Loading…
Cancel
Save