[C] Fix issue with enum initialization lists

Summary: Fail quietly to translate enum initializer lists.

Reviewed By: grievejia

Differential Revision: D5574903

fbshipit-source-id: 6d3c4ea
master
Andrzej Kotulski 7 years ago committed by Facebook Github Bot
parent 88b74d524d
commit 6ca447fa6a

@ -1950,7 +1950,11 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let init_field field_exp_typ stmt =
init_expr_trans trans_state field_exp_typ stmt_info (Some stmt)
in
List.map2_exn field_exps stmts ~f:init_field
match List.map2 field_exps stmts ~f:init_field with
| Ok result
-> result
| Unequal_lengths
-> (* This can happen with union initializers. Skip them for now *) []
and initListExpr_builtin_trans trans_state stmt_info stmts var_exp var_typ =
let stmt = match stmts with [s] -> s | _ -> assert false in

@ -0,0 +1,18 @@
/*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
union U {
int f1;
int f2[3];
};
void union_initialize_FIXME() {
union U set_f1 = {.f1 = 2};
union U set_f2 = {.f2 = {1, 2, 3}};
union U set_f1_implicit = {1};
}

@ -0,0 +1,10 @@
/* @generated */
digraph iCFG {
"union_initialize_FIXME.324b85335f5d2e418a28cb97eb896f20_1" [label="1: Start union_initialize_FIXME\nFormals: \nLocals: set_f1_implicit:U set_f2:U set_f1:U \n DECLARE_LOCALS(&return,&set_f1_implicit,&set_f2,&set_f1); [line 14]\n " color=yellow style=filled]
"union_initialize_FIXME.324b85335f5d2e418a28cb97eb896f20_1" -> "union_initialize_FIXME.324b85335f5d2e418a28cb97eb896f20_2" ;
"union_initialize_FIXME.324b85335f5d2e418a28cb97eb896f20_2" [label="2: Exit union_initialize_FIXME \n " color=yellow style=filled]
}
Loading…
Cancel
Save