Unified · Split
| @@ -5233,7 +5233,7 @@ static int is_compatible_types(CType *type1, CType *type2) · 5232 unmodified lines | |||
| 5233 | return 1; | 5233 | return 1; |
| 5234 | return is_compatible_types(type1, type2); | 5234 | return is_compatible_types(type1, type2); |
| 5235 | } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { | 5235 | } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) { |
| 5236 | return (t2 == t1); | 5236 | return (type1->ref == type2->ref); |
| 5237 | } else if (bt1 == VT_FUNC) { | 5237 | } else if (bt1 == VT_FUNC) { |
| 5238 | if (bt2 != VT_FUNC) | 5238 | if (bt2 != VT_FUNC) |
| 5239 | return 0; | 5239 | return 0; |
| @@ -5357,26 +5357,41 @@ void type_to_str(char *buf, int buf_size, · 117 unmodified lines | |||
| 5357 | 5357 | ||
| 5358 | /* verify type compatibility to store vtop in 'dt' type, and generate | 5358 | /* verify type compatibility to store vtop in 'dt' type, and generate |
| 5359 | casts if needed. */ | 5359 | casts if needed. */ |
| 5360 | void gen_assign_cast(CType *dt) | 5360 | static void gen_assign_cast(CType *dt) |
| 5361 | { | 5361 | { |
| 5362 | CType *st; | 5362 | CType *st; |
| 5363 | char buf1[256], buf2[256]; | 5363 | char buf1[256], buf2[256]; |
| 5364 | int dbt, sbt; | ||
| 5364 | 5365 | ||
| 5365 | st = &vtop->type; /* source type */ | 5366 | st = &vtop->type; /* source type */ |
| 5366 | if ((dt->t & VT_BTYPE) == VT_PTR) { | 5367 | dbt = dt->t & VT_BTYPE; |
| 5368 | sbt = st->t & VT_BTYPE; | ||
| 5369 | if (dbt == VT_PTR) { | ||
| 5367 | /* special cases for pointers */ | 5370 | /* special cases for pointers */ |
| 5368 | /* a function is implicitely a function pointer */ | 5371 | /* a function is implicitely a function pointer */ |
| 5369 | if ((st->t & VT_BTYPE) == VT_FUNC) { | 5372 | if (sbt == VT_FUNC) { |
| 5370 | if (!is_compatible_types(pointed_type(dt), st)) | 5373 | if (!is_compatible_types(pointed_type(dt), st)) |
| 5371 | goto error; | 5374 | goto error; |
| 5372 | else | 5375 | else |
| 5373 | goto type_ok; | 5376 | goto type_ok; |
| 5374 | } | 5377 | } |
| 5375 | /* '0' can also be a pointer */ | 5378 | /* '0' can also be a pointer */ |
| 5376 | if ((st->t & VT_BTYPE) == VT_INT && | 5379 | if (sbt == VT_INT && |
| 5377 | ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) && | 5380 | ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) && |
| 5378 | vtop->c.i == 0) | 5381 | vtop->c.i == 0) |
| 5379 | goto type_ok; | 5382 | goto type_ok; |
| 5383 | /* accept implicit pointer to integer cast with warning */ | ||
| 5384 | if (sbt == VT_BYTE || sbt == VT_SHORT || | ||
| 5385 | sbt == VT_INT || sbt == VT_LLONG) { | ||
| 5386 | warning("assignment makes pointer from integer without a cast"); | ||
| 5387 | goto type_ok; | ||
| 5388 | } | ||
| 5389 | } else if (dbt == VT_BYTE || dbt == VT_SHORT || | ||
| 5390 | dbt == VT_INT || dbt == VT_LLONG) { | ||
| 5391 | if (sbt == VT_PTR || sbt == VT_FUNC) { | ||
| 5392 | warning("assignment makes integer from pointer without a cast"); | ||
| 5393 | goto type_ok; | ||
| 5394 | } | ||
| 5380 | } | 5395 | } |
| 5381 | if (!is_compatible_types(dt, st)) { | 5396 | if (!is_compatible_types(dt, st)) { |
| 5382 | error: | 5397 | error: |
| @@ -5641,6 +5656,8 @@ static void struct_decl(CType *type, int u) · 258 unmodified lines | |||
| 5641 | if (a == TOK_ENUM) { | 5656 | if (a == TOK_ENUM) { |
| 5642 | for(;;) { | 5657 | for(;;) { |
| 5643 | v = tok; | 5658 | v = tok; |
| 5659 | if (v < TOK_UIDENT) | ||
| 5660 | expect("identifier"); | ||
| 5644 | next(); | 5661 | next(); |
| 5645 | if (tok == '=') { | 5662 | if (tok == '=') { |
| 5646 | next(); | 5663 | next(); |
| @@ -5649,9 +5666,11 @@ static void struct_decl(CType *type, int u) · 2 unmodified lines | |||
| 5649 | /* enum symbols have static storage */ | 5666 | /* enum symbols have static storage */ |
| 5650 | ss = sym_push(v, &int_type, VT_CONST, c); | 5667 | ss = sym_push(v, &int_type, VT_CONST, c); |
| 5651 | ss->type.t |= VT_STATIC; | 5668 | ss->type.t |= VT_STATIC; |
| 5652 | if (tok == ',') | 5669 | if (tok != ',') |
| 5653 | next(); | 5670 | break; |
| 5671 | next(); | ||
| 5654 | c++; | 5672 | c++; |
| 5673 | /* NOTE: we accept a trailing comma */ | ||
| 5655 | if (tok == '}') | 5674 | if (tok == '}') |
| 5656 | break; | 5675 | break; |
| 5657 | } | 5676 | } |