[clang] Do not crash on translating captured variables of lambda expressions

Reviewed By: jvillard

Differential Revision: D8802240

fbshipit-source-id: daab5eb
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 1f7a6e53fb
commit 8ce394942b

@ -2680,9 +2680,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let lambda_pname = CMethod_trans.get_procname_from_cpp_lambda context lei_lambda_decl in let lambda_pname = CMethod_trans.get_procname_from_cpp_lambda context lei_lambda_decl in
let typ = CType_decl.qual_type_to_sil_type context.tenv qual_type in let typ = CType_decl.qual_type_to_sil_type context.tenv qual_type in
let get_captured_pvar_typ decl_ref = let get_captured_pvar_typ decl_ref =
Option.value_exn CVar_decl.sil_var_of_captured_var context stmt_info.Clang_ast_t.si_source_range procname
(CVar_decl.sil_var_of_captured_var context stmt_info.Clang_ast_t.si_source_range procname decl_ref
decl_ref)
in in
let translate_capture_init (pvar, typ) init_decl = let translate_capture_init (pvar, typ) init_decl =
match init_decl with match init_decl with
@ -2724,15 +2723,21 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
false false
in in
match (lci_captured_var, lci_init_captured_vardecl) with match (lci_captured_var, lci_init_captured_vardecl) with
| Some captured_var_decl_ref, Some init_decl -> | Some captured_var_decl_ref, Some init_decl -> (
(* capture and init *) match (* capture and init *)
let pvar_typ = get_captured_pvar_typ captured_var_decl_ref in get_captured_pvar_typ captured_var_decl_ref with
( translate_capture_init pvar_typ init_decl :: trans_results_acc | Some pvar_typ ->
, (Exp.Lvar (fst pvar_typ), fst pvar_typ, snd pvar_typ) :: captured_vars_acc ) ( translate_capture_init pvar_typ init_decl :: trans_results_acc
| Some captured_var_decl_ref, None -> , (Exp.Lvar (fst pvar_typ), fst pvar_typ, snd pvar_typ) :: captured_vars_acc )
(* just capture *) | None ->
let pvar_typ = get_captured_pvar_typ captured_var_decl_ref in (trans_results_acc, captured_vars_acc) )
translate_normal_capture ~is_by_ref pvar_typ acc | Some captured_var_decl_ref, None -> (
match (* just capture *)
get_captured_pvar_typ captured_var_decl_ref with
| Some pvar_typ ->
translate_normal_capture ~is_by_ref pvar_typ acc
| None ->
(trans_results_acc, captured_vars_acc) )
| None, None -> | None, None ->
if lci_capture_this then if lci_capture_this then
(* captured [this] *) (* captured [this] *)

Loading…
Cancel
Save