mirror of
git://repo.or.cz/tinycc.git
synced 2026-07-08 04:18:40 +08:00
Check enum range for typed enums
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
This commit is contained in:
parent
6ca6328e29
commit
8c59fd3cb6
14
tccgen.c
14
tccgen.c
@ -4431,13 +4431,19 @@ do_decl:
|
|||||||
/* non empty enums are not allowed */
|
/* non empty enums are not allowed */
|
||||||
ps = &s->next;
|
ps = &s->next;
|
||||||
if (u == VT_ENUM) {
|
if (u == VT_ENUM) {
|
||||||
long long ll = 0, pl = 0, nl = 0;
|
long long ll = 0, pl = 0, nl = 0, ni = 0, pi = 0;
|
||||||
|
unsigned long long mu = 0;
|
||||||
CType t;
|
CType t;
|
||||||
t.ref = s;
|
t.ref = s;
|
||||||
/* enum symbols have static storage */
|
/* enum symbols have static storage */
|
||||||
t.t = VT_INT|VT_STATIC|VT_ENUM_VAL;
|
t.t = VT_INT|VT_STATIC|VT_ENUM_VAL;
|
||||||
if (bt)
|
if (bt) {
|
||||||
t.t = bt|VT_STATIC|VT_ENUM_VAL;
|
t.t = bt|VT_STATIC|VT_ENUM_VAL;
|
||||||
|
mu = 1llu << (type_size(&t, &align) * 8 - 1);
|
||||||
|
pi = mu - 1;
|
||||||
|
ni = -mu;
|
||||||
|
mu = (mu << 1) - 1u;
|
||||||
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
v = tok;
|
v = tok;
|
||||||
if (v < TOK_UIDENT)
|
if (v < TOK_UIDENT)
|
||||||
@ -4451,6 +4457,10 @@ do_decl:
|
|||||||
next();
|
next();
|
||||||
ll = expr_const64();
|
ll = expr_const64();
|
||||||
}
|
}
|
||||||
|
if (bt && (t.t & VT_UNSIGNED ? (unsigned long long)ll > mu
|
||||||
|
: ll < ni || ll > pi))
|
||||||
|
tcc_error("enumerator value outside the range of underlying type '%s'",
|
||||||
|
get_tok_str(v, NULL));
|
||||||
ss = sym_push(v, &t, VT_CONST, 0);
|
ss = sym_push(v, &t, VT_CONST, 0);
|
||||||
ss->enum_val = ll;
|
ss->enum_val = ll;
|
||||||
*ps = ss, ps = &ss->next;
|
*ps = ss, ps = &ss->next;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user