mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-04 21:26:36 +08:00
tcc: use a common type qualifier mask
Some checks are pending
build and test / test-x86_64-linux (push) Waiting to run
build and test / test-x86_64-osx (push) Waiting to run
build and test / test-aarch64-osx (push) Waiting to run
build and test / test-x86_64-win32 (push) Waiting to run
build and test / test-i386-win32 (push) Waiting to run
build and test / test-arm64-win32 (push) Waiting to run
build and test / test-armv7-linux (push) Waiting to run
build and test / test-aarch64-linux (push) Waiting to run
build and test / test-riscv64-linux (push) Waiting to run
build and test / test-i386-linux (push) Waiting to run
Some checks are pending
build and test / test-x86_64-linux (push) Waiting to run
build and test / test-x86_64-osx (push) Waiting to run
build and test / test-aarch64-osx (push) Waiting to run
build and test / test-x86_64-win32 (push) Waiting to run
build and test / test-i386-win32 (push) Waiting to run
build and test / test-arm64-win32 (push) Waiting to run
build and test / test-armv7-linux (push) Waiting to run
build and test / test-aarch64-linux (push) Waiting to run
build and test / test-riscv64-linux (push) Waiting to run
build and test / test-i386-linux (push) Waiting to run
Create a new bitmask value, VT_QUAL, to represent both of the qualifier bits (VT_CONSTANT and VT_VOLATILE) that TCC retains and handles uniformly. This is a pure refactoring that simplifies the code and makes it easier to add other qualifiers in future.
This commit is contained in:
parent
48f54e5969
commit
c9829912d7
@ -307,7 +307,7 @@ ST_FUNC void load(int r, SValue *sv)
|
|||||||
fr = sv->r;
|
fr = sv->r;
|
||||||
ft = sv->type.t & ~VT_DEFSIGN;
|
ft = sv->type.t & ~VT_DEFSIGN;
|
||||||
fc = sv->c.i;
|
fc = sv->c.i;
|
||||||
ft &= ~(VT_VOLATILE | VT_CONSTANT);
|
ft &= ~VT_QUAL;
|
||||||
v = fr & VT_VALMASK;
|
v = fr & VT_VALMASK;
|
||||||
|
|
||||||
#if defined CONFIG_TCC_PIC
|
#if defined CONFIG_TCC_PIC
|
||||||
|
|||||||
1
tcc.h
1
tcc.h
@ -1063,6 +1063,7 @@ struct filespec {
|
|||||||
#define VT_BITFIELD 0x0080 /* bitfield modifier */
|
#define VT_BITFIELD 0x0080 /* bitfield modifier */
|
||||||
#define VT_CONSTANT 0x0100 /* const modifier */
|
#define VT_CONSTANT 0x0100 /* const modifier */
|
||||||
#define VT_VOLATILE 0x0200 /* volatile modifier */
|
#define VT_VOLATILE 0x0200 /* volatile modifier */
|
||||||
|
#define VT_QUAL (VT_CONSTANT | VT_VOLATILE)
|
||||||
#define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
|
#define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
|
||||||
#define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */
|
#define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */
|
||||||
|
|
||||||
|
|||||||
4
tccdbg.c
4
tccdbg.c
@ -1787,7 +1787,7 @@ static int stabs_struct_find(TCCState *s1, Sym *t, int *p_id)
|
|||||||
|
|
||||||
static int remove_type_info(int type)
|
static int remove_type_info(int type)
|
||||||
{
|
{
|
||||||
type &= ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE | VT_VLA);
|
type &= ~(VT_STORAGE | VT_QUAL | VT_VLA);
|
||||||
if ((type & VT_BTYPE) != VT_BYTE)
|
if ((type & VT_BTYPE) != VT_BYTE)
|
||||||
type &= ~VT_DEFSIGN;
|
type &= ~VT_DEFSIGN;
|
||||||
if (!(type & VT_BITFIELD) && (type & VT_STRUCT_MASK) > VT_ENUM)
|
if (!(type & VT_BITFIELD) && (type & VT_STRUCT_MASK) > VT_ENUM)
|
||||||
@ -2112,7 +2112,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
|
|||||||
dwarf_data4(dwarf_info_section, sub_type - dwarf_info.start);
|
dwarf_data4(dwarf_info_section, sub_type - dwarf_info.start);
|
||||||
dwarf_uleb128(dwarf_info_section, t->type.ref->c - 1);
|
dwarf_uleb128(dwarf_info_section, t->type.ref->c - 1);
|
||||||
s = t->type.ref;
|
s = t->type.ref;
|
||||||
type = s->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);
|
type = s->type.t & ~(VT_STORAGE | VT_QUAL);
|
||||||
if (type != (VT_PTR | VT_ARRAY))
|
if (type != (VT_PTR | VT_ARRAY))
|
||||||
break;
|
break;
|
||||||
t = s;
|
t = s;
|
||||||
|
|||||||
21
tccgen.c
21
tccgen.c
@ -2822,7 +2822,7 @@ static inline int is_null_pointer(SValue *p)
|
|||||||
((p->type.t & VT_BTYPE) == VT_PTR &&
|
((p->type.t & VT_BTYPE) == VT_PTR &&
|
||||||
(PTR_SIZE == 4 ? (uint32_t)p->c.i == 0 : p->c.i == 0) &&
|
(PTR_SIZE == 4 ? (uint32_t)p->c.i == 0 : p->c.i == 0) &&
|
||||||
((pointed_type(&p->type)->t & VT_BTYPE) == VT_VOID) &&
|
((pointed_type(&p->type)->t & VT_BTYPE) == VT_VOID) &&
|
||||||
0 == (pointed_type(&p->type)->t & (VT_CONSTANT | VT_VOLATILE))
|
0 == (pointed_type(&p->type)->t & VT_QUAL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2871,8 +2871,8 @@ static int compare_types(CType *type1, CType *type2, int unqualified)
|
|||||||
t2 = type2->t & VT_TYPE;
|
t2 = type2->t & VT_TYPE;
|
||||||
if (unqualified) {
|
if (unqualified) {
|
||||||
/* strip qualifiers before comparing */
|
/* strip qualifiers before comparing */
|
||||||
t1 &= ~(VT_CONSTANT | VT_VOLATILE);
|
t1 &= ~VT_QUAL;
|
||||||
t2 &= ~(VT_CONSTANT | VT_VOLATILE);
|
t2 &= ~VT_QUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Default Vs explicit signedness only matters for char */
|
/* Default Vs explicit signedness only matters for char */
|
||||||
@ -3490,7 +3490,7 @@ error:
|
|||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
vtop->type = *type;
|
vtop->type = *type;
|
||||||
vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY | VT_TLS );
|
vtop->type.t &= ~ ( VT_QUAL | VT_ARRAY | VT_TLS );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return type size as known at compile time. Put alignment at 'a' */
|
/* return type size as known at compile time. Put alignment at 'a' */
|
||||||
@ -3573,7 +3573,7 @@ static int type_qualifiers(CType *type)
|
|||||||
{
|
{
|
||||||
while (type->t & VT_ARRAY)
|
while (type->t & VT_ARRAY)
|
||||||
type = pointed_type(type);
|
type = pointed_type(type);
|
||||||
return type->t & (VT_CONSTANT | VT_VOLATILE);
|
return type->t & VT_QUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* modify type so that its it is a pointer to type. */
|
/* modify type so that its it is a pointer to type. */
|
||||||
@ -3641,8 +3641,7 @@ static void verify_assign_cast(CType *dt)
|
|||||||
if (is_compatible_types(type1, type2))
|
if (is_compatible_types(type1, type2))
|
||||||
break;
|
break;
|
||||||
for (qualwarn = lvl = 0;; ++lvl) {
|
for (qualwarn = lvl = 0;; ++lvl) {
|
||||||
if (((type2->t & VT_CONSTANT) && !(type1->t & VT_CONSTANT)) ||
|
if ((type2->t & ~type1->t) & VT_QUAL)
|
||||||
((type2->t & VT_VOLATILE) && !(type1->t & VT_VOLATILE)))
|
|
||||||
qualwarn = 1;
|
qualwarn = 1;
|
||||||
dbt = type1->t & (VT_BTYPE|VT_LONG);
|
dbt = type1->t & (VT_BTYPE|VT_LONG);
|
||||||
sbt = type2->t & (VT_BTYPE|VT_LONG);
|
sbt = type2->t & (VT_BTYPE|VT_LONG);
|
||||||
@ -4969,7 +4968,7 @@ static int parse_btype(CType *type, AttributeDef *ad, int ignore_label)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t &= ~(VT_BTYPE|VT_LONG);
|
t &= ~(VT_BTYPE|VT_LONG);
|
||||||
u = t & ~(VT_CONSTANT | VT_VOLATILE), t ^= u;
|
u = t & ~VT_QUAL, t ^= u;
|
||||||
type->t = (s->type.t & ~VT_TYPEDEF) | u;
|
type->t = (s->type.t & ~VT_TYPEDEF) | u;
|
||||||
type->ref = s->type.ref;
|
type->ref = s->type.ref;
|
||||||
if (t)
|
if (t)
|
||||||
@ -5016,7 +5015,7 @@ static inline void convert_parameter_type(CType *pt)
|
|||||||
/* apply the conversions required for an expression value */
|
/* apply the conversions required for an expression value */
|
||||||
static inline void convert_expression_type(CType *pt)
|
static inline void convert_expression_type(CType *pt)
|
||||||
{
|
{
|
||||||
pt->t &= ~(VT_CONSTANT | VT_VOLATILE);
|
pt->t &= ~VT_QUAL;
|
||||||
convert_parameter_type(pt);
|
convert_parameter_type(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5121,7 +5120,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
|||||||
skip(')');
|
skip(')');
|
||||||
/* A function return value has the unqualified version of its
|
/* A function return value has the unqualified version of its
|
||||||
declared type. */
|
declared type. */
|
||||||
type->t &= ~(VT_CONSTANT | VT_VOLATILE);
|
type->t &= ~VT_QUAL;
|
||||||
/* some ancient pre-K&R C allows a function to return an array
|
/* some ancient pre-K&R C allows a function to return an array
|
||||||
and the array brackets to be put after the arguments, such
|
and the array brackets to be put after the arguments, such
|
||||||
that "int c()[]" means something like "int[] c()" */
|
that "int c()[]" means something like "int[] c()" */
|
||||||
@ -6197,7 +6196,7 @@ special_math_val:
|
|||||||
/* field */
|
/* field */
|
||||||
if (tok == TOK_ARROW)
|
if (tok == TOK_ARROW)
|
||||||
indir();
|
indir();
|
||||||
qualifiers = vtop->type.t & (VT_CONSTANT | VT_VOLATILE);
|
qualifiers = vtop->type.t & VT_QUAL;
|
||||||
test_lvalue();
|
test_lvalue();
|
||||||
/* expect pointer on structure */
|
/* expect pointer on structure */
|
||||||
next();
|
next();
|
||||||
|
|||||||
@ -377,7 +377,7 @@ void load(int r, SValue *sv)
|
|||||||
SValue v1;
|
SValue v1;
|
||||||
|
|
||||||
fr = sv->r;
|
fr = sv->r;
|
||||||
ft = sv->type.t & ~(VT_DEFSIGN|VT_VOLATILE|VT_CONSTANT);
|
ft = sv->type.t & ~(VT_DEFSIGN|VT_QUAL);
|
||||||
fc = sv->c.i;
|
fc = sv->c.i;
|
||||||
|
|
||||||
if (fc != sv->c.i && (fr & VT_SYM))
|
if (fc != sv->c.i && (fr & VT_SYM))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user