| @@ -81,7 +81,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td); · 80 unmodified lines |
| 81 | 81 | static void parse_expr_type(CType *type); |
| 82 | 82 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); |
| 83 | 83 | static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); |
| 84 | | −static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope); |
| 84 | +static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); |
| 85 | 85 | static int decl0(int l, int is_for_loop_init); |
| 86 | 86 | static void expr_eq(void); |
| 87 | 87 | static void unary_type(CType *type); |
| @@ -158,7 +158,6 @@ static inline Sym *sym_malloc(void) · 70 unmodified lines |
| 158 | 158 | ST_INLN void sym_free(Sym *sym) |
| 159 | 159 | { |
| 160 | 160 | sym->next = sym_free_first; |
| 161 | | − tcc_free(sym->asm_label); |
| 162 | 161 | sym_free_first = sym; |
| 163 | 162 | } |
| 164 | 163 | |
| @@ -173,7 +172,7 @@ ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c) · 8 unmodified lines |
| 173 | 172 | get_tok_str(v, NULL)); |
| 174 | 173 | } |
| 175 | 174 | s = sym_malloc(); |
| 176 | | − s->asm_label = NULL; |
| 175 | + s->asm_label = 0; |
| 177 | 176 | s->v = v; |
| 178 | 177 | s->type.t = t; |
| 179 | 178 | s->type.ref = NULL; |
| @@ -443,10 +442,8 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r) · 263 unmodified lines |
| 443 | 442 | return s; |
| 444 | 443 | } |
| 445 | 444 | |
| 446 | | −/* define a new external reference to a symbol 'v' with alternate asm |
| 447 | | − name 'asm_label' of type 'u'. 'asm_label' is equal to NULL if there |
| 448 | | − is no alternate name (most cases) */ |
| 449 | | −static Sym *external_sym(int v, CType *type, int r, char *asm_label) |
| 445 | +/* define a new external reference to a symbol 'v' */ |
| 446 | +static Sym *external_sym(int v, CType *type, int r) |
| 450 | 447 | { |
| 451 | 448 | Sym *s; |
| 452 | 449 | |
| @@ -454,7 +451,6 @@ static Sym *external_sym(int v, CType *type, int r, char *asm_label) · 1 unmodified line |
| 454 | 451 | if (!s) { |
| 455 | 452 | /* push forward reference */ |
| 456 | 453 | s = sym_push(v, type, r | VT_CONST | VT_SYM, 0); |
| 457 | | − s->asm_label = asm_label ? tcc_strdup(asm_label) : 0; |
| 458 | 454 | s->type.t |= VT_EXTERN; |
| 459 | 455 | } else if (s->type.ref == func_old_type.ref) { |
| 460 | 456 | s->type.ref = type->ref; |
| @@ -3386,16 +3382,21 @@ ST_FUNC void parse_asm_str(CString *astr) · 2925 unmodified lines |
| 3386 | 3382 | cstr_ccat(astr, '\0'); |
| 3387 | 3383 | } |
| 3388 | 3384 | |
| 3389 | | −/* Parse an asm label and return the label |
| 3390 | | − * Don't forget to free the CString in the caller! */ |
| 3391 | | −static void asm_label_instr(CString *astr) |
| 3385 | +/* Parse an asm label and return the token */ |
| 3386 | +static int asm_label_instr(void) |
| 3392 | 3387 | { |
| 3388 | + int v; |
| 3389 | + CString astr; |
| 3390 | + |
| 3393 | 3391 | next(); |
| 3394 | | − parse_asm_str(astr); |
| 3392 | + parse_asm_str(&astr); |
| 3395 | 3393 | skip(')'); |
| 3396 | 3394 | #ifdef ASM_DEBUG |
| 3397 | | − printf("asm_alias: \"%s\"\n", (char *)astr->data); |
| 3395 | + printf("asm_alias: \"%s\"\n", (char *)astr.data); |
| 3398 | 3396 | #endif |
| 3397 | + v = tok_alloc(astr.data, astr.size - 1)->tok; |
| 3398 | + cstr_free(&astr); |
| 3399 | + return v; |
| 3399 | 3400 | } |
| 3400 | 3401 | |
| 3401 | 3402 | static void post_type(CType *type, AttributeDef *ad) |
| @@ -3801,7 +3802,7 @@ ST_FUNC void unary(void) · 399 unmodified lines |
| 3801 | 3802 | mk_pointer(&type); |
| 3802 | 3803 | type.t |= VT_ARRAY; |
| 3803 | 3804 | memset(&ad, 0, sizeof(AttributeDef)); |
| 3804 | | − decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, NULL, 0); |
| 3805 | + decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0); |
| 3805 | 3806 | break; |
| 3806 | 3807 | case '(': |
| 3807 | 3808 | next(); |
| @@ -3820,7 +3821,7 @@ ST_FUNC void unary(void) · 12 unmodified lines |
| 3820 | 3821 | if (!(type.t & VT_ARRAY)) |
| 3821 | 3822 | r |= lvalue_type(type.t); |
| 3822 | 3823 | memset(&ad, 0, sizeof(AttributeDef)); |
| 3823 | | − decl_initializer_alloc(&type, &ad, r, 1, 0, NULL, 0); |
| 3824 | + decl_initializer_alloc(&type, &ad, r, 1, 0, 0); |
| 3824 | 3825 | } else { |
| 3825 | 3826 | if (sizeof_caller) { |
| 3826 | 3827 | vpush(&type); |
| @@ -4199,7 +4200,7 @@ ST_FUNC void unary(void) · 372 unmodified lines |
| 4199 | 4200 | break; |
| 4200 | 4201 | } |
| 4201 | 4202 | if (!s) |
| 4202 | | − tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, NULL)); |
| 4203 | + tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, &tokc)); |
| 4203 | 4204 | /* add field offset to pointer */ |
| 4204 | 4205 | vtop->type = char_pointer_type; /* change type to 'char *' */ |
| 4205 | 4206 | vpushi(s->c); |
| @@ -5742,14 +5743,12 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1536 unmodified lines |
| 5742 | 5743 | /* parse an initializer for type 't' if 'has_init' is non zero, and |
| 5743 | 5744 | allocate space in local or global data space ('r' is either |
| 5744 | 5745 | VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated |
| 5745 | | − variable 'v' with an associated name represented by 'asm_label' of |
| 5746 | | − scope 'scope' is declared before initializers are parsed. If 'v' is |
| 5747 | | − zero, then a reference to the new object is put in the value stack. |
| 5748 | | − If 'has_init' is 2, a special parsing is done to handle string |
| 5749 | | − constants. */ |
| 5746 | + variable 'v' of scope 'scope' is declared before initializers |
| 5747 | + are parsed. If 'v' is zero, then a reference to the new object |
| 5748 | + is put in the value stack. If 'has_init' is 2, a special parsing |
| 5749 | + is done to handle string constants. */ |
| 5750 | 5750 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, |
| 5751 | | − int has_init, int v, char *asm_label, |
| 5752 | | − int scope) |
| 5751 | + int has_init, int v, int scope) |
| 5753 | 5752 | { |
| 5754 | 5753 | int size, align, addr, data_offset; |
| 5755 | 5754 | int level; |
| @@ -5931,7 +5930,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 175 unmodified lines |
| 5931 | 5930 | if (v) { |
| 5932 | 5931 | if (scope != VT_CONST || !sym) { |
| 5933 | 5932 | sym = sym_push(v, type, r | VT_SYM, 0); |
| 5934 | | − sym->asm_label = asm_label ? tcc_strdup(asm_label) : 0; |
| 5933 | + sym->asm_label = ad->asm_label; |
| 5935 | 5934 | } |
| 5936 | 5935 | /* update symbol definition */ |
| 5937 | 5936 | if (sec) { |
| @@ -6162,7 +6161,6 @@ static int decl0(int l, int is_for_loop_init) · 224 unmodified lines |
| 6162 | 6161 | CType type, btype; |
| 6163 | 6162 | Sym *sym; |
| 6164 | 6163 | AttributeDef ad; |
| 6165 | | − char *asm_label = 0; // associated asm label |
| 6166 | 6164 | |
| 6167 | 6165 | while (1) { |
| 6168 | 6166 | if (!parse_btype(&btype, &ad)) { |
| @@ -6218,17 +6216,12 @@ static int decl0(int l, int is_for_loop_init) · 49 unmodified lines |
| 6218 | 6216 | func_decl_list(sym); |
| 6219 | 6217 | } |
| 6220 | 6218 | |
| 6221 | | − tcc_free(asm_label); |
| 6222 | | − asm_label = 0; |
| 6223 | 6219 | if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) { |
| 6224 | | − CString astr; |
| 6225 | | − |
| 6226 | | − asm_label_instr(&astr); |
| 6227 | | − asm_label = tcc_strdup(astr.data); |
| 6228 | | − cstr_free(&astr); |
| 6229 | | − |
| 6220 | + ad.asm_label = asm_label_instr(); |
| 6230 | 6221 | /* parse one last attribute list, after asm label */ |
| 6231 | 6222 | parse_attribute(&ad); |
| 6223 | + if (tok == '{') |
| 6224 | + expect(";"); |
| 6232 | 6225 | } |
| 6233 | 6226 | |
| 6234 | 6227 | if (ad.a.weak) |
| @@ -6371,7 +6364,8 @@ static int decl0(int l, int is_for_loop_init) · 136 unmodified lines |
| 6371 | 6364 | /* NOTE: as GCC, uninitialized global static |
| 6372 | 6365 | arrays of null size are considered as |
| 6373 | 6366 | extern */ |
| 6374 | | − sym = external_sym(v, &type, r, asm_label); |
| 6367 | + sym = external_sym(v, &type, r); |
| 6368 | + sym->asm_label = ad.asm_label; |
| 6375 | 6369 | |
| 6376 | 6370 | if (ad.alias_target) { |
| 6377 | 6371 | Section tsec; |
| @@ -6393,14 +6387,12 @@ static int decl0(int l, int is_for_loop_init) · 15 unmodified lines |
| 6393 | 6387 | r |= l; |
| 6394 | 6388 | if (has_init) |
| 6395 | 6389 | next(); |
| 6396 | | − decl_initializer_alloc(&type, &ad, r, has_init, v, asm_label, l); |
| 6390 | + decl_initializer_alloc(&type, &ad, r, has_init, v, l); |
| 6397 | 6391 | } |
| 6398 | 6392 | } |
| 6399 | 6393 | if (tok != ',') { |
| 6400 | | − if (is_for_loop_init) { |
| 6401 | | − tcc_free(asm_label); |
| 6394 | + if (is_for_loop_init) |
| 6402 | 6395 | return 1; |
| 6403 | | − } |
| 6404 | 6396 | skip(';'); |
| 6405 | 6397 | break; |
| 6406 | 6398 | } |
| @@ -6409,7 +6401,6 @@ static int decl0(int l, int is_for_loop_init) · 2 unmodified lines |
| 6409 | 6401 | ad.a.aligned = 0; |
| 6410 | 6402 | } |
| 6411 | 6403 | } |
| 6412 | | − tcc_free(asm_label); |
| 6413 | 6404 | return 0; |
| 6414 | 6405 | } |
| 6415 | 6406 | |