Skip to content

Commit b31e430

Browse files
akosthekissyichoi
authored andcommitted
Add explicit casts to enum-to-integer conversions (#2467)
Clang 6 is more picky about implicit conversions and complains about loss of presicion and/or change of signedness. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
1 parent d7cb48d commit b31e430

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

jerry-core/debugger/debugger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ jerry_debugger_send_data (jerry_debugger_header_type_t type, /**< message type *
900900

901901
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_type_t, message_type_p);
902902

903-
message_type_p->type = type;
903+
message_type_p->type = (uint8_t) type;
904904
memcpy (message_type_p + 1, data, size);
905905

906906
jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + size);

jerry-core/ecma/builtin-objects/ecma-builtins.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
297297
built_in_props_p = &((ecma_extended_object_t *) obj_p)->u.built_in;
298298
}
299299

300-
built_in_props_p->id = obj_builtin_id;
301-
built_in_props_p->routine_id = obj_builtin_id;
300+
built_in_props_p->id = (uint8_t) obj_builtin_id;
301+
built_in_props_p->routine_id = (uint16_t) obj_builtin_id;
302302
built_in_props_p->instantiated_bitset[0] = 0;
303303

304304
if (property_count > 32)
@@ -528,7 +528,7 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
528528
JERRY_ASSERT (routine_id >= ECMA_BUILTIN_ID__COUNT);
529529

530530
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
531-
ext_func_obj_p->u.built_in.id = builtin_id;
531+
ext_func_obj_p->u.built_in.id = (uint8_t) builtin_id;
532532
ext_func_obj_p->u.built_in.routine_id = routine_id;
533533
ext_func_obj_p->u.built_in.instantiated_bitset[0] = 0;
534534

jerry-core/ecma/operations/ecma-typedarray-object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ ecma_typedarray_create_object_with_length (ecma_length_t array_length, /**< leng
249249
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
250250

251251
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
252-
ext_object_p->u.pseudo_array.u1.class_id = class_id;
252+
ext_object_p->u.pseudo_array.u1.class_id = (uint16_t) class_id;
253253
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_TYPEDARRAY;
254254
ext_object_p->u.pseudo_array.extra_info = element_size_shift;
255255
ext_object_p->u.pseudo_array.u2.arraybuffer = new_arraybuffer_p;
@@ -285,7 +285,7 @@ ecma_typedarray_create_object_with_buffer (ecma_object_t *arraybuffer_p, /**< th
285285
ecma_object_t *object_p = ecma_create_object (proto_p, object_size, ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
286286

287287
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
288-
ext_object_p->u.pseudo_array.u1.class_id = class_id;
288+
ext_object_p->u.pseudo_array.u1.class_id = (uint16_t) class_id;
289289
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_TYPEDARRAY;
290290
ext_object_p->u.pseudo_array.extra_info = element_size_shift;
291291
ext_object_p->u.pseudo_array.u2.arraybuffer = ecma_make_object_value (arraybuffer_p);

jerry-core/parser/js/js-lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */
558558
break;
559559
}
560560

561-
context_p->token.type = keyword_p->type;
561+
context_p->token.type = (uint8_t) keyword_p->type;
562562
break;
563563
}
564564
keyword_p++;

jerry-core/parser/js/js-parser-expr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */
203203
break;
204204
}
205205
}
206-
parser_emit_cbc (context_p, opcode);
206+
parser_emit_cbc (context_p, (uint16_t) opcode);
207207
}
208208
} /* parser_emit_unary_lvalue_opcode */
209209

@@ -1091,7 +1091,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
10911091
}
10921092
}
10931093

1094-
parser_emit_cbc_literal_from_token (context_p, opcode);
1094+
parser_emit_cbc_literal_from_token (context_p, (uint16_t) opcode);
10951095
break;
10961096
}
10971097
case LEXER_KEYW_FUNCTION:
@@ -1770,7 +1770,7 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */
17701770
if (cbc_flags[opcode] & CBC_HAS_LITERAL_ARG)
17711771
{
17721772
uint16_t index = parser_stack_pop_uint16 (context_p);
1773-
parser_emit_cbc_literal (context_p, opcode, index);
1773+
parser_emit_cbc_literal (context_p, (uint16_t) opcode, index);
17741774

17751775
if (opcode == CBC_ASSIGN_PROP_THIS_LITERAL
17761776
&& (context_p->stack_depth >= context_p->stack_limit))
@@ -1830,7 +1830,7 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */
18301830
continue;
18311831
}
18321832
}
1833-
parser_emit_cbc (context_p, opcode);
1833+
parser_emit_cbc (context_p, (uint16_t) opcode);
18341834
}
18351835
} /* parser_process_binary_opcodes */
18361836

@@ -1916,7 +1916,7 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
19161916
opcode = CBC_BRANCH_IF_TRUE_FORWARD;
19171917
}
19181918

1919-
parser_emit_cbc_forward_branch (context_p, opcode, &cond_branch);
1919+
parser_emit_cbc_forward_branch (context_p, (uint16_t) opcode, &cond_branch);
19201920

19211921
lexer_next_token (context_p);
19221922
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);

jerry-core/parser/js/js-parser-statm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ parser_parse_do_while_statement_end (parser_context_t *context_p) /**< context *
660660
parser_stack_iterator_skip (&iterator, sizeof (parser_loop_statement_t));
661661
parser_stack_iterator_read (&iterator, &do_while_statement, sizeof (parser_do_while_statement_t));
662662

663-
parser_emit_cbc_backward_branch (context_p, opcode, do_while_statement.start_offset);
663+
parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, do_while_statement.start_offset);
664664
}
665665
else
666666
{
@@ -759,7 +759,7 @@ parser_parse_while_statement_end (parser_context_t *context_p) /**< context */
759759
parser_stack_pop (context_p, NULL, 1 + sizeof (parser_loop_statement_t) + sizeof (parser_while_statement_t));
760760
parser_stack_iterator_init (context_p, &context_p->last_statement);
761761

762-
parser_emit_cbc_backward_branch (context_p, opcode, while_statement.start_offset);
762+
parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, while_statement.start_offset);
763763
parser_set_breaks_to_current_position (context_p, loop.branch_list_p);
764764

765765
parser_set_range (context_p, &range);
@@ -1027,7 +1027,7 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */
10271027
parser_stack_pop (context_p, NULL, 1 + sizeof (parser_loop_statement_t) + sizeof (parser_for_statement_t));
10281028
parser_stack_iterator_init (context_p, &context_p->last_statement);
10291029

1030-
parser_emit_cbc_backward_branch (context_p, opcode, for_statement.start_offset);
1030+
parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, for_statement.start_offset);
10311031
parser_set_breaks_to_current_position (context_p, loop.branch_list_p);
10321032

10331033
parser_set_range (context_p, &range);
@@ -1427,7 +1427,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */
14271427
if (lexer_compare_identifier_to_current (context_p, &label_statement.label_ident))
14281428
{
14291429
label_statement.break_list_p = parser_emit_cbc_forward_branch_item (context_p,
1430-
opcode,
1430+
(uint16_t) opcode,
14311431
label_statement.break_list_p);
14321432
parser_stack_iterator_write (&iterator, &label_statement, sizeof (parser_label_statement_t));
14331433
lexer_next_token (context_p);
@@ -1470,7 +1470,7 @@ parser_parse_break_statement (parser_context_t *context_p) /**< context */
14701470
parser_stack_iterator_skip (&iterator, 1);
14711471
parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t));
14721472
loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p,
1473-
opcode,
1473+
(uint16_t) opcode,
14741474
loop.branch_list_p);
14751475
parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t));
14761476
return;
@@ -1526,7 +1526,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */
15261526
parser_stack_iterator_skip (&loop_iterator, 1);
15271527
parser_stack_iterator_read (&loop_iterator, &loop, sizeof (parser_loop_statement_t));
15281528
loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p,
1529-
opcode,
1529+
(uint16_t) opcode,
15301530
loop.branch_list_p);
15311531
loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK;
15321532
parser_stack_iterator_write (&loop_iterator, &loop, sizeof (parser_loop_statement_t));
@@ -1583,7 +1583,7 @@ parser_parse_continue_statement (parser_context_t *context_p) /**< context */
15831583
parser_stack_iterator_skip (&iterator, 1);
15841584
parser_stack_iterator_read (&iterator, &loop, sizeof (parser_loop_statement_t));
15851585
loop.branch_list_p = parser_emit_cbc_forward_branch_item (context_p,
1586-
opcode,
1586+
(uint16_t) opcode,
15871587
loop.branch_list_p);
15881588
loop.branch_list_p->branch.offset |= CBC_HIGHEST_BIT_MASK;
15891589
parser_stack_iterator_write (&iterator, &loop, sizeof (parser_loop_statement_t));

jerry-core/parser/js/js-parser-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
117117

118118
JERRY_ASSERT (opcode < CBC_EXT_END);
119119
flags = cbc_ext_flags[opcode];
120-
parser_emit_two_bytes (context_p, CBC_EXT_OPCODE, opcode);
120+
parser_emit_two_bytes (context_p, CBC_EXT_OPCODE, (uint8_t) opcode);
121121
context_p->byte_code_size += 2;
122122
}
123123

jerry-core/parser/js/js-parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
18571857
}
18581858

18591859
/* Storing the opcode */
1860-
*dst_p++ = opcode;
1860+
*dst_p++ = (uint8_t) opcode;
18611861
real_offset++;
18621862
PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset);
18631863
flags = cbc_flags[opcode];
@@ -1879,7 +1879,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
18791879
branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (ext_opcode);
18801880

18811881
/* Storing the extended opcode */
1882-
*dst_p++ = ext_opcode;
1882+
*dst_p++ = (uint8_t) ext_opcode;
18831883
opcode_p++;
18841884
real_offset++;
18851885
PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset);

jerry-ext/include/jerryscript-ext/arg.impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct
9494
func = jerryx_arg_transform_ ## type; \
9595
} \
9696
} \
97-
const jerryx_arg_int_option_t int_option = { .round = round_flag, .clamp = clamp_flag }; \
97+
const jerryx_arg_int_option_t int_option = { .round = (uint8_t) round_flag, .clamp = (uint8_t) clamp_flag }; \
9898
return (jerryx_arg_t) \
9999
{ \
100100
.func = func, \

jerry-port/default/default-fatal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ void jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
7272
}
7373
#endif /* !DISABLE_EXTRA_API */
7474

75-
exit (code);
75+
exit ((int) code);
7676
} /* jerry_port_fatal */

0 commit comments

Comments
 (0)