Mentions légales du service

Skip to content
Snippets Groups Projects
Commit feb58d03 authored by Thierry Martinez's avatar Thierry Martinez
Browse files

Convert array subscript on pointers to pointer arithmetic

parent beca8f96
No related branches found
No related tags found
No related merge requests found
Pipeline #730293 failed
...@@ -596,6 +596,11 @@ with type 'a Applicative.t = 'a Applicative.t = struct ...@@ -596,6 +596,11 @@ with type 'a Applicative.t = 'a Applicative.t = struct
{ record_decl with fields = name_anonymous_fields record_decl.fields }, { record_decl with fields = name_anonymous_fields record_decl.fields },
Free_monoid.zero Free_monoid.zero
let is_pointer_type (ty : Clang.Type.t) =
match ty.desc with
| Pointer _ -> true
| _ -> false
let hook : let hook :
type a . a Refl.refl -> (a -> env -> a * accu) -> (a -> env -> a * accu) = type a . a Refl.refl -> (a -> env -> a * accu) -> (a -> env -> a * accu) =
fun refl super x env -> fun refl super x env ->
...@@ -624,9 +629,18 @@ with type 'a Applicative.t = 'a Applicative.t = struct ...@@ -624,9 +629,18 @@ with type 'a Applicative.t = 'a Applicative.t = struct
Visit.visit [%refl: Clang.Ast.expr] [] Visit.visit [%refl: Clang.Ast.expr] []
cond { env with in_condition = true } in cond { env with in_condition = true } in
Call { callee; args = [cond] }, cond_stmts Call { callee; args = [cond] }, cond_stmts
| UnaryExpr { kind = SizeOf; argument } -> | UnaryExpr { kind = SizeOf; argument } ->
visit_unary_expr_size_of argument env visit_unary_expr_size_of argument env
| _ -> super x env | ArraySubscript { base; index }
when is_pointer_type (Clang.Type.of_node base) ->
let x' : Clang.Ast.expr_desc = UnaryOperator {
kind = Deref;
operand = { base with desc = BinaryOperator {
lhs = base;
kind = Add;
rhs = index; }}} in
super x' env
| _ -> super x env
end end
| Clang.Ast.Refl_decl_desc -> | Clang.Ast.Refl_decl_desc ->
begin match x with begin match x with
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment