Unified · Split
| @@ -2541,6 +2541,7 @@ static void preprocess(int is_bof) · 2540 unmodified lines | ||
| 2541 | 2541 | case TOK_ERROR: |
| 2542 | 2542 | case TOK_WARNING: |
| 2543 | 2543 | c = tok; |
| 2544 | + ch = file->buf_ptr[0]; | |
| 2544 | 2545 | skip_spaces(); |
| 2545 | 2546 | q = buf; |
| 2546 | 2547 | while (ch != '\n' && ch != CH_EOF) { |
| @@ -5567,12 +5568,16 @@ void parse_attribute(AttributeDef *ad) · 3020 unmodified lines | ||
| 5567 | 5568 | break; |
| 5568 | 5569 | case TOK_ALIGNED: |
| 5569 | 5570 | case TOK___ALIGNED__: |
| 5570 | − skip('('); | |
| 5571 | − n = expr_const(); | |
| 5572 | − if (n <= 0 || (n & (n - 1)) != 0) | |
| 5573 | − error("alignment must be a positive power of two"); | |
| 5571 | + if (tok == '(') { | |
| 5572 | + next(); | |
| 5573 | + n = expr_const(); | |
| 5574 | + if (n <= 0 || (n & (n - 1)) != 0) | |
| 5575 | + error("alignment must be a positive power of two"); | |
| 5576 | + skip(')'); | |
| 5577 | + } else { | |
| 5578 | + n = MAX_ALIGN; | |
| 5579 | + } | |
| 5574 | 5580 | ad->aligned = n; |
| 5575 | − skip(')'); | |
| 5576 | 5581 | break; |
| 5577 | 5582 | case TOK_UNUSED: |
| 5578 | 5583 | case TOK___UNUSED__: |
| @@ -7263,8 +7268,9 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 1684 unmodified lines | ||
| 7263 | 7268 | static void init_putv(CType *type, Section *sec, unsigned long c, |
| 7264 | 7269 | int v, int expr_type) |
| 7265 | 7270 | { |
| 7266 | − int saved_global_expr, bt; | |
| 7271 | + int saved_global_expr, bt, bit_pos, bit_size; | |
| 7267 | 7272 | void *ptr; |
| 7273 | + unsigned long long bit_mask; | |
| 7268 | 7274 | |
| 7269 | 7275 | switch(expr_type) { |
| 7270 | 7276 | case EXPR_VAL: |
| @@ -7291,19 +7297,30 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 20 unmodified lines | ||
| 7291 | 7297 | gen_assign_cast(type); |
| 7292 | 7298 | bt = type->t & VT_BTYPE; |
| 7293 | 7299 | ptr = sec->data + c; |
| 7300 | + /* XXX: make code faster ? */ | |
| 7301 | + if (!(type->t & VT_BITFIELD)) { | |
| 7302 | + bit_pos = 0; | |
| 7303 | + bit_size = 32; | |
| 7304 | + bit_mask = -1LL; | |
| 7305 | + } else { | |
| 7306 | + bit_pos = (vtop->type.t >> VT_STRUCT_SHIFT) & 0x3f; | |
| 7307 | + bit_size = (vtop->type.t >> (VT_STRUCT_SHIFT + 6)) & 0x3f; | |
| 7308 | + bit_mask = (1LL << bit_size) - 1; | |
| 7309 | + } | |
| 7294 | 7310 | if ((vtop->r & VT_SYM) && |
| 7295 | 7311 | (bt == VT_BYTE || |
| 7296 | 7312 | bt == VT_SHORT || |
| 7297 | 7313 | bt == VT_DOUBLE || |
| 7298 | 7314 | bt == VT_LDOUBLE || |
| 7299 | − bt == VT_LLONG)) | |
| 7315 | + bt == VT_LLONG || | |
| 7316 | + (bt == VT_INT && bit_size != 32))) | |
| 7300 | 7317 | error("initializer element is not computable at load time"); |
| 7301 | 7318 | switch(bt) { |
| 7302 | 7319 | case VT_BYTE: |
| 7303 | − *(char *)ptr = vtop->c.i; | |
| 7320 | + *(char *)ptr |= (vtop->c.i & bit_mask) << bit_pos; | |
| 7304 | 7321 | break; |
| 7305 | 7322 | case VT_SHORT: |
| 7306 | − *(short *)ptr = vtop->c.i; | |
| 7323 | + *(short *)ptr |= (vtop->c.i & bit_mask) << bit_pos; | |
| 7307 | 7324 | break; |
| 7308 | 7325 | case VT_DOUBLE: |
| 7309 | 7326 | *(double *)ptr = vtop->c.d; |
| @@ -7312,13 +7329,13 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 2 unmodified lines | ||
| 7312 | 7329 | *(long double *)ptr = vtop->c.ld; |
| 7313 | 7330 | break; |
| 7314 | 7331 | case VT_LLONG: |
| 7315 | − *(long long *)ptr = vtop->c.ll; | |
| 7332 | + *(long long *)ptr |= (vtop->c.ll & bit_mask) << bit_pos; | |
| 7316 | 7333 | break; |
| 7317 | 7334 | default: |
| 7318 | 7335 | if (vtop->r & VT_SYM) { |
| 7319 | 7336 | greloc(sec, vtop->sym, c, R_DATA_32); |
| 7320 | 7337 | } |
| 7321 | − *(int *)ptr = vtop->c.i; | |
| 7338 | + *(int *)ptr |= (vtop->c.i & bit_mask) << bit_pos; | |
| 7322 | 7339 | break; |
| 7323 | 7340 | } |
| 7324 | 7341 | vtop--; |
| @@ -7467,7 +7484,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 142 unmodified lines | ||
| 7467 | 7484 | /* NOTE: the previous test is a specific case for automatic |
| 7468 | 7485 | struct/union init */ |
| 7469 | 7486 | /* XXX: union needs only one init */ |
| 7470 | − /* XXX: handle bit fields */ | |
| 7471 | 7487 | no_oblock = 1; |
| 7472 | 7488 | if (first || tok == '{') { |
| 7473 | 7489 | skip('{'); |
| @@ -7480,8 +7496,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 6 unmodified lines | ||
| 7480 | 7496 | n = s->c; |
| 7481 | 7497 | while (tok != '}') { |
| 7482 | 7498 | decl_designator(type, sec, c, NULL, &f, size_only); |
| 7483 | − /* XXX: bitfields ? */ | |
| 7484 | − /* fill with zero between fields */ | |
| 7485 | 7499 | index = f->c; |
| 7486 | 7500 | if (!size_only && array_length < index) { |
| 7487 | 7501 | init_putz(type, sec, c + array_length, |
| @@ -7490,12 +7504,12 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 2 unmodified lines | ||
| 7490 | 7504 | index = index + type_size(&f->type, &align1); |
| 7491 | 7505 | if (index > array_length) |
| 7492 | 7506 | array_length = index; |
| 7493 | − if (no_oblock && f->next == NULL) | |
| 7507 | + f = f->next; | |
| 7508 | + if (no_oblock && f == NULL) | |
| 7494 | 7509 | break; |
| 7495 | 7510 | if (tok == '}') |
| 7496 | 7511 | break; |
| 7497 | 7512 | skip(','); |
| 7498 | − f = f->next; | |
| 7499 | 7513 | } |
| 7500 | 7514 | /* put zeros at the end */ |
| 7501 | 7515 | if (!size_only && array_length < n) { |
| @@ -8843,7 +8857,7 @@ static int64_t getclock_us(void) · 1341 unmodified lines | ||
| 8843 | 8857 | |
| 8844 | 8858 | void help(void) |
| 8845 | 8859 | { |
| 8846 | − printf("tcc version 0.9.13 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | |
| 8860 | + printf("tcc version 0.9.14 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | |
| 8847 | 8861 | "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n" |
| 8848 | 8862 | " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n" |
| 8849 | 8863 | " [--] infile1 [infile2... --] [infile_args...]\n" |