mirror of
https://github.com/TinyCC/tinycc.git
synced 2025-11-16 04:24:45 +00:00
Some fixes and cleanups
tcc.h, tccgen.c: Add and use IS_BT_ARRAY tccpp.c: free memory when size is 0 in realloc code tccdbg.c: move common code to seperate function remove_type_info
This commit is contained in:
1
tcc.h
1
tcc.h
@@ -1098,6 +1098,7 @@ struct filespec {
|
||||
|
||||
/* base type is array (from typedef/typeof) */
|
||||
#define VT_BT_ARRAY (6 << VT_STRUCT_SHIFT)
|
||||
#define IS_BT_ARRAY(t) ((t & VT_STRUCT_MASK) == VT_BT_ARRAY)
|
||||
|
||||
/* general: set/get the pseudo-bitfield value for bit-mask M */
|
||||
#define BFVAL(M,N) ((unsigned)((M) & ~((M) << 1)) * (N))
|
||||
|
||||
30
tccdbg.c
30
tccdbg.c
@@ -1769,6 +1769,16 @@ static int stabs_struct_find(TCCState *s1, Sym *t, int *p_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remove_type_info(int type)
|
||||
{
|
||||
type &= ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
||||
if ((type & VT_BTYPE) != VT_BYTE)
|
||||
type &= ~VT_DEFSIGN;
|
||||
if (!(type & VT_BITFIELD) && (type & VT_STRUCT_MASK) > VT_ENUM)
|
||||
type &= ~VT_STRUCT_MASK;
|
||||
return type;
|
||||
}
|
||||
|
||||
static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
|
||||
{
|
||||
int type;
|
||||
@@ -1778,11 +1788,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
|
||||
CString str;
|
||||
|
||||
for (;;) {
|
||||
type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
||||
if ((type & VT_BTYPE) != VT_BYTE)
|
||||
type &= ~VT_DEFSIGN;
|
||||
if (!(type & VT_BITFIELD) && (type & VT_STRUCT_MASK) > VT_ENUM)
|
||||
type &= ~VT_STRUCT_MASK;
|
||||
type = remove_type_info (t->type.t);
|
||||
if (type == VT_PTR || type == (VT_PTR | VT_ARRAY))
|
||||
n++, t = t->type.ref;
|
||||
else
|
||||
@@ -1861,9 +1867,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
|
||||
cstr_printf (result, "%d=", ++debug_next_type);
|
||||
t = s;
|
||||
for (;;) {
|
||||
type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
||||
if ((type & VT_BTYPE) != VT_BYTE)
|
||||
type &= ~VT_DEFSIGN;
|
||||
type = remove_type_info (t->type.t);
|
||||
if (type == VT_PTR)
|
||||
cstr_printf (result, "%d=*", ++debug_next_type);
|
||||
else if (type == (VT_PTR | VT_ARRAY))
|
||||
@@ -1901,11 +1905,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
|
||||
if (new_file)
|
||||
put_new_file(s1);
|
||||
for (;;) {
|
||||
type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
||||
if ((type & VT_BTYPE) != VT_BYTE)
|
||||
type &= ~VT_DEFSIGN;
|
||||
if (!(type & VT_BITFIELD) && (type & VT_STRUCT_MASK) > VT_ENUM)
|
||||
type &= ~VT_STRUCT_MASK;
|
||||
type = remove_type_info (t->type.t);
|
||||
if (type == VT_PTR || type == (VT_PTR | VT_ARRAY))
|
||||
t = t->type.ref;
|
||||
else
|
||||
@@ -2052,9 +2052,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
|
||||
e = NULL;
|
||||
t = s;
|
||||
for (;;) {
|
||||
type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
||||
if ((type & VT_BTYPE) != VT_BYTE)
|
||||
type &= ~VT_DEFSIGN;
|
||||
type = remove_type_info (t->type.t);
|
||||
if (type == VT_PTR) {
|
||||
i = dwarf_info_section->data_offset;
|
||||
if (retval == debug_type)
|
||||
|
||||
2
tccgen.c
2
tccgen.c
@@ -8204,7 +8204,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
||||
we will overwrite the unknown size by the real one for
|
||||
this decl. We need to unshare the ref symbol holding
|
||||
that size. */
|
||||
if (type->t & VT_BT_ARRAY)
|
||||
if (IS_BT_ARRAY(type->t))
|
||||
type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c);
|
||||
p.flex_array_ref = type->ref;
|
||||
|
||||
|
||||
5
tccpp.c
5
tccpp.c
@@ -159,6 +159,7 @@ static void *tcc_realloc_impl(void *p, unsigned size)
|
||||
PP_ALLOC_INSERT(alloc);
|
||||
return alloc + 1;
|
||||
}
|
||||
tcc_free(alloc);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
@@ -372,8 +373,10 @@ tail_call:
|
||||
PP_ALLOC_INSERT(alloc);
|
||||
ret = alloc + 1;
|
||||
}
|
||||
else
|
||||
else {
|
||||
tcc_free(alloc);
|
||||
ret = NULL;
|
||||
}
|
||||
}
|
||||
#ifdef TAL_INFO
|
||||
al->nb_missed++;
|
||||
|
||||
Reference in New Issue
Block a user