Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ int fputc(int c, FILE *stream)
#define IS_CHUNK_GET_FREED(size) (size & CHUNK_SIZE_FREED_MASK)

typedef struct chunk {
struct chunk *next;
struct chunk *prev;
struct chunk *next, *prev;
int size;
} chunk_t;

Expand Down
24 changes: 8 additions & 16 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ typedef struct {
typedef struct ref_block ref_block_t;

struct ref_block_list {
ref_block_t *head;
ref_block_t *tail;
ref_block_t *head, *tail;
};

typedef struct ref_block_list ref_block_list_t;
Expand All @@ -276,8 +275,7 @@ typedef struct insn insn_t;

typedef struct use_chain_node {
insn_t *insn;
struct use_chain_node *next;
struct use_chain_node *prev;
struct use_chain_node *next, *prev;
} use_chain_t;

typedef struct var var_t;
Expand Down Expand Up @@ -306,8 +304,7 @@ struct var {
int subscripts_idx;
rename_t rename;
ref_block_list_t ref_block_list; /* blocks which kill variable */
use_chain_t *users_head;
use_chain_t *users_tail;
use_chain_t *users_head, *users_tail;
struct insn *last_assign;
int consumed;
bool is_ternary_ret;
Expand Down Expand Up @@ -408,8 +405,7 @@ struct phi_operand {
typedef struct phi_operand phi_operand_t;

struct insn {
struct insn *next;
struct insn *prev;
struct insn *next, *prev;
int idx;
opcode_t opcode;
var_t *rd;
Expand All @@ -423,13 +419,11 @@ struct insn {
};

typedef struct {
insn_t *head;
insn_t *tail;
insn_t *head, *tail;
} insn_list_t;

typedef struct {
ph2_ir_t *head;
ph2_ir_t *tail;
ph2_ir_t *head, *tail;
} ph2_ir_list_t;

typedef enum { NEXT, ELSE, THEN } bb_connection_type_t;
Expand All @@ -448,8 +442,7 @@ struct symbol {
typedef struct symbol symbol_t;

typedef struct {
symbol_t *head;
symbol_t *tail;
symbol_t *head, *tail;
} symbol_list_t;

struct basic_block {
Expand Down Expand Up @@ -519,8 +512,7 @@ struct func {
};

typedef struct {
func_t *head;
func_t *tail;
func_t *head, *tail;
} func_list_t;

typedef struct {
Expand Down
51 changes: 51 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,31 @@ void read_global_statement(void)
read_full_var_decl(v, 0, 1);
v->offset = size;
size += size_var(v);

/* Handle multiple variable declarations with same base type */
while (lex_accept(T_comma)) {
if (i >= MAX_FIELDS)
error("Too many struct fields");

var_t *nv = &type->fields[i++];
nv->type = v->type;
nv->var_name[0] = '\0';
nv->is_ptr = 0;
nv->is_func = false;
nv->is_global = false;
nv->array_size = 0;
nv->offset = 0;
nv->init_val = 0;
nv->liveness = 0;
nv->in_loop = 0;
nv->base = NULL;
nv->subscript = 0;
nv->subscripts_idx = 0;
read_inner_var_decl(nv, 0, 1);
nv->offset = size;
size += size_var(nv);
}

lex_expect(T_semicolon);
} while (!lex_accept(T_close_curly));

Expand Down Expand Up @@ -2922,6 +2947,32 @@ void read_global_statement(void)
read_full_var_decl(v, 0, 1);
v->offset = size;
size += size_var(v);

/* Handle multiple variable declarations with same base type
*/
while (lex_accept(T_comma)) {
if (i >= MAX_FIELDS)
error("Too many struct fields");

var_t *nv = &type->fields[i++];
nv->type = v->type;
nv->var_name[0] = '\0';
nv->is_ptr = 0;
nv->is_func = false;
nv->is_global = false;
nv->array_size = 0;
nv->offset = 0;
nv->init_val = 0;
nv->liveness = 0;
nv->in_loop = 0;
nv->base = NULL;
nv->subscript = 0;
nv->subscripts_idx = 0;
read_inner_var_decl(nv, 0, 1);
nv->offset = size;
size += size_var(nv);
}

lex_expect(T_semicolon);
} while (!lex_accept(T_close_curly));
}
Expand Down
14 changes: 14 additions & 0 deletions tests/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ int main() {
}
EOF

# struct with multiple pointer declarations in same line
try_ 42 << EOF
typedef struct chunk {
struct chunk *next, *prev;
int size;
} chunk_t;

int main() {
chunk_t c;
c.size = 42;
return c.size;
}
EOF

# arrays
try_ 12 << EOF
int nth_of(int *a, int i) {
Expand Down