Skip to content

Commit 38ab5f6

Browse files
author
grischka
committed
tccgen: more of scope hacks
* case 1: local scope of 'ff' int main() { int ff = 123; { int ff(int): ff(456) }} * case 2: linkage of a static extern symbol (older gcc did allow that) static int ff(int); int main() { int ff(int): ff(456) } Also: - cleanup enum, let sym_push() handle redefinition - just mark incomplete array base types, unshare only when needed (in decl_initializer_alloc()) - fix sizeof empty array (= 0) : int ii[] = {}; - rename 'Sym' members used by __attribute__((cleanup(f)))
1 parent ce4de96 commit 38ab5f6

File tree

10 files changed

+288
-144
lines changed

10 files changed

+288
-144
lines changed

tcc.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,17 @@ typedef struct Sym {
552552
CType type; /* associated type */
553553
union {
554554
struct Sym *next; /* next related symbol (for fields and anoms) */
555-
int *e; /* expanded token stream */
555+
int *e; /* expanded token stream with preprocessor macros */
556556
int asm_label; /* associated asm label */
557557
struct Sym *cleanupstate; /* in defined labels */
558558
int *vla_array_str; /* vla array code */
559559
};
560560
struct Sym *prev; /* prev symbol in stack */
561-
struct Sym *prev_tok; /* previous symbol for this token */
561+
union {
562+
struct Sym *prev_tok; /* previous symbol for this token */
563+
struct Sym *cleanup_sym; /* symbol from __attribute__((cleanup())) */
564+
struct Sym *cleanup_label; /* label in 'pending_gotos' chain */
565+
};
562566
} Sym;
563567

564568
/* section definition */
@@ -1074,7 +1078,7 @@ struct filespec {
10741078

10751079
#define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
10761080
#define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
1077-
#define VT_ENUM_VAL (4 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
1081+
#define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
10781082

10791083
#define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
10801084
#define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
@@ -1087,9 +1091,13 @@ struct filespec {
10871091
#define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
10881092

10891093
/* symbol was created by tccasm.c first */
1090-
#define VT_ASM (VT_VOID | 1 << VT_STRUCT_SHIFT)
1091-
#define VT_ASM_FUNC (VT_ASM | 2 << VT_STRUCT_SHIFT)
1092-
#define IS_ASM_SYM(sym) (((sym)->type.t & (VT_BTYPE | VT_ASM)) == VT_ASM)
1094+
#define VT_ASM (VT_VOID | 4 << VT_STRUCT_SHIFT)
1095+
#define VT_ASM_FUNC (VT_VOID | 5 << VT_STRUCT_SHIFT)
1096+
#define IS_ASM_SYM(sym) (((sym)->type.t & ((VT_BTYPE|VT_STRUCT_MASK) & ~(1<<VT_STRUCT_SHIFT))) == VT_ASM)
1097+
#define IS_ASM_FUNC(t) ((t & (VT_BTYPE|VT_STRUCT_MASK)) == VT_ASM_FUNC)
1098+
1099+
/* base type is array (from typedef/typeof) */
1100+
#define VT_BT_ARRAY (6 << VT_STRUCT_SHIFT)
10931101

10941102
/* general: set/get the pseudo-bitfield value for bit-mask M */
10951103
#define BFVAL(M,N) ((unsigned)((M) & ~((M) << 1)) * (N))

tccasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static void asm_parse_directive(TCCState *s1, int global)
842842

843843
if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
844844
if (IS_ASM_SYM(sym))
845-
sym->type.t = (sym->type.t & ~VT_ASM) | VT_ASM_FUNC;
845+
sym->type.t |= VT_ASM_FUNC;
846846
st_type = STT_FUNC;
847847
set_st_type:
848848
if (sym->c) {

0 commit comments

Comments
 (0)