Skip to content

Commit d471a74

Browse files
committed
Warning fixes.
ISO C99 doesn’t support unnamed structs/unions. Comparison of distinct pointer types lacks a cast. Dereferencing type-punned pointer will break strict-aliasing rules. Type of bit-field ‘ext’ is a GCC extension. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent 977bfa5 commit d471a74

19 files changed

+140
-139
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ project (Jerry C ASM)
278278
endforeach()
279279
endmacro()
280280

281-
add_jerry_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
282-
add_jerry_compile_flags(-pedantic -Wno-stack-protector -Wno-attributes)
281+
add_jerry_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations pedantic)
282+
add_jerry_compile_flags(-Wno-stack-protector -Wno-attributes)
283283
if(CMAKE_COMPILER_IS_GNUCC)
284284
add_jerry_compile_warnings(logical-op)
285285
else()

jerry-core/ecma/base/ecma-globals.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ typedef enum
294294
*/
295295
typedef struct
296296
{
297-
mem_cpointer_t getter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to getter object */
298-
mem_cpointer_t setter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to setter object */
297+
__extension__ mem_cpointer_t getter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to getter object */
298+
__extension__ mem_cpointer_t setter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to setter object */
299299
} ecma_getter_setter_pointers_t;
300300

301301
/**
@@ -307,7 +307,7 @@ typedef struct __attr_packed___ ecma_property_t
307307
unsigned int type : 2;
308308

309309
/** Compressed pointer to next property */
310-
mem_cpointer_t next_property_p : ECMA_POINTER_FIELD_WIDTH;
310+
__extension__ mem_cpointer_t next_property_p : ECMA_POINTER_FIELD_WIDTH;
311311

312312
/** Property's details (depending on Type) */
313313
union
@@ -319,7 +319,7 @@ typedef struct __attr_packed___ ecma_property_t
319319
ecma_value_t value : ECMA_VALUE_SIZE;
320320

321321
/** Compressed pointer to property's name (pointer to String) */
322-
mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
322+
__extension__ mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
323323

324324
/** Flag indicating whether the property is registered in LCache */
325325
unsigned int is_lcached : 1;
@@ -338,7 +338,7 @@ typedef struct __attr_packed___ ecma_property_t
338338
struct __attr_packed___ ecma_named_accessor_property_t
339339
{
340340
/** Compressed pointer to property's name (pointer to String) */
341-
mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
341+
__extension__ mem_cpointer_t name_p : ECMA_POINTER_FIELD_WIDTH;
342342

343343
/** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */
344344
unsigned int enumerable : 1;
@@ -350,7 +350,7 @@ typedef struct __attr_packed___ ecma_property_t
350350
unsigned int is_lcached : 1;
351351

352352
/** Compressed pointer to pair of pointers - to property's getter and setter */
353-
mem_cpointer_t getter_setter_pair_cp : ECMA_POINTER_FIELD_WIDTH;
353+
__extension__ mem_cpointer_t getter_setter_pair_cp : ECMA_POINTER_FIELD_WIDTH;
354354
} named_accessor_property;
355355

356356
/** Description of internal property */
@@ -795,10 +795,10 @@ typedef struct ecma_string_t
795795
lit_cpointer_t lit_cp;
796796

797797
/** Compressed pointer to an ecma_collection_header_t */
798-
mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
798+
__extension__ mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
799799

800800
/** Compressed pointer to an ecma_number_t */
801-
mem_cpointer_t number_cp : ECMA_POINTER_FIELD_WIDTH;
801+
__extension__ mem_cpointer_t number_cp : ECMA_POINTER_FIELD_WIDTH;
802802

803803
/** UInt32-represented number placed locally in the descriptor */
804804
uint32_t uint32_number;

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
978978
{
979979
case ECMA_STRING_CONTAINER_LIT_TABLE:
980980
{
981-
JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value);
981+
JERRY_ASSERT (string1_p->u.lit_cp.u.packed_value != string2_p->u.lit_cp.u.packed_value);
982982
return false;
983983
}
984984
case ECMA_STRING_CONTAINER_MAGIC_STRING:

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
13881388

13891389
for (uint32_t i = const_literal_end; i < literal_end; i++)
13901390
{
1391-
mem_cpointer_t bytecode_cpointer = literal_start_p[i].value.base_cp;
1391+
mem_cpointer_t bytecode_cpointer = literal_start_p[i].u.value.base_cp;
13921392
ecma_compiled_code_t *bytecode_literal_p = ECMA_GET_NON_NULL_POINTER (ecma_compiled_code_t,
13931393
bytecode_cpointer);
13941394

jerry-core/ecma/operations/ecma-objects-arguments.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ ecma_op_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function
138138
indx++)
139139
{
140140
// i.
141-
if (literal_p[indx].packed_value == MEM_CP_NULL)
141+
if (literal_p[indx].u.packed_value == MEM_CP_NULL)
142142
{
143143
continue;
144144
}

jerry-core/ecma/operations/ecma-reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ typedef struct
3737
ecma_value_t base;
3838

3939
/** referenced name */
40-
mem_cpointer_t referenced_name_cp : ECMA_POINTER_FIELD_WIDTH;
40+
__extension__ mem_cpointer_t referenced_name_cp : ECMA_POINTER_FIELD_WIDTH;
4141

4242
/** strict reference flag */
4343
unsigned int is_strict : 1;

jerry-core/jerry-api.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ typedef struct jerry_api_value_t
118118

119119
uint32_t v_uint32; /**< number converted 32-bit unsigned integer */
120120

121-
union
122-
{
123-
jerry_api_string_t *v_string; /**< pointer to a JS string */
124-
jerry_api_object_t *v_object; /**< pointer to a JS object */
125-
};
126-
};
121+
jerry_api_string_t *v_string; /**< pointer to a JS string */
122+
jerry_api_object_t *v_object; /**< pointer to a JS object */
123+
124+
} u;
127125
} jerry_api_value_t;
128126

129127
/**

jerry-core/jerry.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jerry_api_value_is_object (const jerry_api_value_t *value_p) /**< pointer to api
205205
bool
206206
jerry_api_value_is_function (const jerry_api_value_t *value_p) /**< pointer to api value */
207207
{
208-
return jerry_api_value_is_object (value_p) && jerry_api_is_function (value_p->v_object);
208+
return jerry_api_value_is_object (value_p) && jerry_api_is_function (value_p->u.v_object);
209209
} /* jerry_api_value_is_function */
210210

211211
/**
@@ -217,7 +217,7 @@ bool
217217
jerry_api_get_boolean_value (const jerry_api_value_t *value_p) /**< pointer to api value */
218218
{
219219
JERRY_ASSERT (jerry_api_value_is_boolean (value_p));
220-
return value_p->v_bool;
220+
return value_p->u.v_bool;
221221
} /* jerry_api_get_boolean_value */
222222

223223
/**
@@ -237,15 +237,15 @@ jerry_api_get_number_value (const jerry_api_value_t *value_p) /**< pointer to ap
237237
JERRY_ASSERT (jerry_api_value_is_number (value_p));
238238
if (value_p->type == JERRY_API_DATA_TYPE_UINT32)
239239
{
240-
return value_p->v_uint32;
240+
return value_p->u.v_uint32;
241241
}
242242
else if (value_p->type == JERRY_API_DATA_TYPE_FLOAT32)
243243
{
244-
return value_p->v_float32;
244+
return value_p->u.v_float32;
245245
}
246246
else
247247
{
248-
return value_p->v_float64;
248+
return value_p->u.v_float64;
249249
}
250250
} /* jerry_api_get_number_value */
251251

@@ -258,7 +258,7 @@ jerry_api_string_t *
258258
jerry_api_get_string_value (const jerry_api_value_t *value_p) /**< pointer to api value */
259259
{
260260
JERRY_ASSERT (jerry_api_value_is_string (value_p));
261-
return value_p->v_string;
261+
return value_p->u.v_string;
262262
} /* jerry_api_get_string_value */
263263

264264
/**
@@ -270,7 +270,7 @@ jerry_api_object_t *
270270
jerry_api_get_object_value (const jerry_api_value_t *value_p) /**< pointer to api value */
271271
{
272272
JERRY_ASSERT (jerry_api_value_is_object (value_p));
273-
return value_p->v_object;
273+
return value_p->u.v_object;
274274
} /* jerry_api_get_object_value */
275275

276276
/**
@@ -318,7 +318,7 @@ jerry_api_create_boolean_value (bool value) /**< bool value from which a jerry_a
318318
{
319319
jerry_api_value_t jerry_val;
320320
jerry_val.type = JERRY_API_DATA_TYPE_BOOLEAN;
321-
jerry_val.v_bool = value;
321+
jerry_val.u.v_bool = value;
322322
return jerry_val;
323323
} /* jerry_api_create_boolean_value */
324324

@@ -332,7 +332,7 @@ jerry_api_create_number_value (double value) /**< double value from which a jerr
332332
{
333333
jerry_api_value_t jerry_val;
334334
jerry_val.type = JERRY_API_DATA_TYPE_FLOAT64;
335-
jerry_val.v_float64 = value;
335+
jerry_val.u.v_float64 = value;
336336
return jerry_val;
337337
} /* jerry_api_create_number_value */
338338

@@ -345,7 +345,7 @@ jerry_api_create_object_value (jerry_api_object_t *value) /**< jerry_api_object_
345345
{
346346
jerry_api_value_t jerry_val;
347347
jerry_val.type = JERRY_API_DATA_TYPE_OBJECT;
348-
jerry_val.v_object = value;
348+
jerry_val.u.v_object = value;
349349
return jerry_val;
350350
} /* jerry_api_create_object_value */
351351

@@ -358,7 +358,7 @@ jerry_api_create_string_value (jerry_api_string_t *value) /**< jerry_api_string_
358358
{
359359
jerry_api_value_t jerry_val;
360360
jerry_val.type = JERRY_API_DATA_TYPE_STRING;
361-
jerry_val.v_string = value;
361+
jerry_val.u.v_string = value;
362362
return jerry_val;
363363
} /* jerry_api_create_string_value */
364364

@@ -391,34 +391,34 @@ jerry_api_convert_ecma_value_to_api_value (jerry_api_value_t *out_value_p, /**<
391391
else if (ecma_is_value_boolean (value))
392392
{
393393
out_value_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
394-
out_value_p->v_bool = ecma_is_value_true (value);
394+
out_value_p->u.v_bool = ecma_is_value_true (value);
395395
}
396396
else if (ecma_is_value_number (value))
397397
{
398398
ecma_number_t *num = ecma_get_number_from_value (value);
399399

400400
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
401401
out_value_p->type = JERRY_API_DATA_TYPE_FLOAT32;
402-
out_value_p->v_float32 = *num;
402+
out_value_p->u.v_float32 = *num;
403403
#elif CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
404404
out_value_p->type = JERRY_API_DATA_TYPE_FLOAT64;
405-
out_value_p->v_float64 = *num;
405+
out_value_p->u.v_float64 = *num;
406406
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */
407407
}
408408
else if (ecma_is_value_string (value))
409409
{
410410
ecma_string_t *str = ecma_get_string_from_value (value);
411411

412412
out_value_p->type = JERRY_API_DATA_TYPE_STRING;
413-
out_value_p->v_string = ecma_copy_or_ref_ecma_string (str);
413+
out_value_p->u.v_string = ecma_copy_or_ref_ecma_string (str);
414414
}
415415
else if (ecma_is_value_object (value))
416416
{
417417
ecma_object_t *obj = ecma_get_object_from_value (value);
418418
ecma_ref_object (obj);
419419

420420
out_value_p->type = JERRY_API_DATA_TYPE_OBJECT;
421-
out_value_p->v_object = obj;
421+
out_value_p->u.v_object = obj;
422422
}
423423
else
424424
{
@@ -453,14 +453,14 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< out:
453453
}
454454
case JERRY_API_DATA_TYPE_BOOLEAN:
455455
{
456-
*out_value_p = ecma_make_simple_value (api_value_p->v_bool ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
456+
*out_value_p = ecma_make_simple_value (api_value_p->u.v_bool ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
457457

458458
break;
459459
}
460460
case JERRY_API_DATA_TYPE_FLOAT32:
461461
{
462462
ecma_number_t *num = ecma_alloc_number ();
463-
*num = (ecma_number_t) (api_value_p->v_float32);
463+
*num = (ecma_number_t) (api_value_p->u.v_float32);
464464

465465
*out_value_p = ecma_make_number_value (num);
466466

@@ -469,7 +469,7 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< out:
469469
case JERRY_API_DATA_TYPE_FLOAT64:
470470
{
471471
ecma_number_t *num = ecma_alloc_number ();
472-
*num = (ecma_number_t) (api_value_p->v_float64);
472+
*num = (ecma_number_t) (api_value_p->u.v_float64);
473473

474474
*out_value_p = ecma_make_number_value (num);
475475

@@ -478,23 +478,23 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< out:
478478
case JERRY_API_DATA_TYPE_UINT32:
479479
{
480480
ecma_number_t *num = ecma_alloc_number ();
481-
*num = (ecma_number_t) (api_value_p->v_uint32);
481+
*num = (ecma_number_t) (api_value_p->u.v_uint32);
482482

483483
*out_value_p = ecma_make_number_value (num);
484484

485485
break;
486486
}
487487
case JERRY_API_DATA_TYPE_STRING:
488488
{
489-
ecma_string_t *str_p = ecma_copy_or_ref_ecma_string (api_value_p->v_string);
489+
ecma_string_t *str_p = ecma_copy_or_ref_ecma_string (api_value_p->u.v_string);
490490

491491
*out_value_p = ecma_make_string_value (str_p);
492492

493493
break;
494494
}
495495
case JERRY_API_DATA_TYPE_OBJECT:
496496
{
497-
ecma_object_t *obj_p = api_value_p->v_object;
497+
ecma_object_t *obj_p = api_value_p->u.v_object;
498498

499499
ecma_ref_object (obj_p);
500500

@@ -654,11 +654,11 @@ jerry_api_release_value (jerry_api_value_t *value_p) /**< API value */
654654

655655
if (value_p->type == JERRY_API_DATA_TYPE_STRING)
656656
{
657-
jerry_api_release_string (value_p->v_string);
657+
jerry_api_release_string (value_p->u.v_string);
658658
}
659659
else if (value_p->type == JERRY_API_DATA_TYPE_OBJECT)
660660
{
661-
jerry_api_release_object (value_p->v_object);
661+
jerry_api_release_object (value_p->u.v_object);
662662
}
663663
} /* jerry_api_release_value */
664664

@@ -2040,28 +2040,28 @@ jerry_snapshot_set_offsets (uint8_t *buffer_p, /**< buffer */
20402040
{
20412041
lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
20422042

2043-
if (literal_start_p[i].packed_value != MEM_CP_NULL)
2043+
if (literal_start_p[i].u.packed_value != MEM_CP_NULL)
20442044
{
2045-
while (current_p->literal_id.packed_value != literal_start_p[i].packed_value)
2045+
while (current_p->literal_id.u.packed_value != literal_start_p[i].u.packed_value)
20462046
{
20472047
current_p++;
20482048
}
20492049

2050-
literal_start_p[i].packed_value = (uint16_t) current_p->literal_offset;
2050+
literal_start_p[i].u.packed_value = (uint16_t) current_p->literal_offset;
20512051
}
20522052
}
20532053

20542054
for (uint32_t i = const_literal_end; i < literal_end; i++)
20552055
{
20562056
compiled_code_map_entry_t *current_p = snapshot_map_entries_p;
20572057

2058-
while (current_p->compiled_code_cp != literal_start_p[i].value.base_cp)
2058+
while (current_p->compiled_code_cp != literal_start_p[i].u.value.base_cp)
20592059
{
20602060
current_p = ECMA_GET_NON_NULL_POINTER (compiled_code_map_entry_t,
20612061
current_p->next_cp);
20622062
}
20632063

2064-
literal_start_p[i].packed_value = (uint16_t) current_p->offset;
2064+
literal_start_p[i].u.packed_value = (uint16_t) current_p->offset;
20652065
}
20662066
}
20672067

@@ -2315,9 +2315,9 @@ snapshot_load_compiled_code (const uint8_t *snapshot_data_p, /**< snapshot data
23152315
{
23162316
lit_mem_to_snapshot_id_map_entry_t *current_p = lit_map_p;
23172317

2318-
if (literal_start_p[i].packed_value != 0)
2318+
if (literal_start_p[i].u.packed_value != 0)
23192319
{
2320-
while (current_p->literal_offset != literal_start_p[i].packed_value)
2320+
while (current_p->literal_offset != literal_start_p[i].u.packed_value)
23212321
{
23222322
current_p++;
23232323
}
@@ -2328,12 +2328,12 @@ snapshot_load_compiled_code (const uint8_t *snapshot_data_p, /**< snapshot data
23282328

23292329
for (uint32_t i = const_literal_end; i < literal_end; i++)
23302330
{
2331-
size_t literal_offset = ((size_t) literal_start_p[i].packed_value) << MEM_ALIGNMENT_LOG;
2331+
size_t literal_offset = ((size_t) literal_start_p[i].u.packed_value) << MEM_ALIGNMENT_LOG;
23322332

23332333
if (literal_offset == offset)
23342334
{
23352335
/* Self reference */
2336-
ECMA_SET_NON_NULL_POINTER (literal_start_p[i].value.base_cp,
2336+
ECMA_SET_NON_NULL_POINTER (literal_start_p[i].u.value.base_cp,
23372337
bytecode_p);
23382338
}
23392339
else
@@ -2344,7 +2344,7 @@ snapshot_load_compiled_code (const uint8_t *snapshot_data_p, /**< snapshot data
23442344
lit_map_p,
23452345
copy_bytecode);
23462346

2347-
ECMA_SET_NON_NULL_POINTER (literal_start_p[i].value.base_cp,
2347+
ECMA_SET_NON_NULL_POINTER (literal_start_p[i].u.value.base_cp,
23482348
literal_bytecode_p);
23492349
}
23502350
}

0 commit comments

Comments
 (0)