History

fixed structure type test - fixed enum parsing - added warning for int/ptr conversions instead of error

bellard committed 23 years ago

Commit b9d94251 parent 7b2721f1 file · +26 −7Browse files

Unified · Split

tcc.c+26−7
@@ -5233,7 +5233,7 @@ static int is_compatible_types(CType *type1, CType *type2) · 5232 unmodified lines
52335233 return 1;
52345234 return is_compatible_types(type1, type2);
52355235 } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
5236− return (t2 == t1);
5236+ return (type1->ref == type2->ref);
52375237 } else if (bt1 == VT_FUNC) {
52385238 if (bt2 != VT_FUNC)
52395239 return 0;
@@ -5357,26 +5357,41 @@ void type_to_str(char *buf, int buf_size, · 117 unmodified lines
53575357
53585358 /* verify type compatibility to store vtop in 'dt' type, and generate
53595359 casts if needed. */
5360−void gen_assign_cast(CType *dt)
5360+static void gen_assign_cast(CType *dt)
53615361 {
53625362 CType *st;
53635363 char buf1[256], buf2[256];
5364+ int dbt, sbt;
53645365
53655366 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) {
53675370 /* special cases for pointers */
53685371 /* a function is implicitely a function pointer */
5369− if ((st->t & VT_BTYPE) == VT_FUNC) {
5372+ if (sbt == VT_FUNC) {
53705373 if (!is_compatible_types(pointed_type(dt), st))
53715374 goto error;
53725375 else
53735376 goto type_ok;
53745377 }
53755378 /* '0' can also be a pointer */
5376− if ((st->t & VT_BTYPE) == VT_INT &&
5379+ if (sbt == VT_INT &&
53775380 ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) &&
53785381 vtop->c.i == 0)
53795382 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+ }
53805395 }
53815396 if (!is_compatible_types(dt, st)) {
53825397 error:
@@ -5641,6 +5656,8 @@ static void struct_decl(CType *type, int u) · 258 unmodified lines
56415656 if (a == TOK_ENUM) {
56425657 for(;;) {
56435658 v = tok;
5659+ if (v < TOK_UIDENT)
5660+ expect("identifier");
56445661 next();
56455662 if (tok == '=') {
56465663 next();
@@ -5649,9 +5666,11 @@ static void struct_decl(CType *type, int u) · 2 unmodified lines
56495666 /* enum symbols have static storage */
56505667 ss = sym_push(v, &int_type, VT_CONST, c);
56515668 ss->type.t |= VT_STATIC;
5652− if (tok == ',')
5653− next();
5669+ if (tok != ',')
5670+ break;
5671+ next();
56545672 c++;
5673+ /* NOTE: we accept a trailing comma */
56555674 if (tok == '}')
56565675 break;
56575676 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t