[hackers] [scc] Make fold a bit more robust || Roberto E. Vargas Caballero
commit eadc7784288c38da564aa1f11602d0c195f5dabb
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Sep 1 19:28:07 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Sep 1 19:28:07 2015 +0200
Make fold a bit more robust
These default cases make that in unknown operations the
behaviour is correct, because in other case the operation
is directly ignored.
diff --git a/cc1/fold.c b/cc1/fold.c
index 4d457d1..e56a88b 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
_AT_@ -86,6 +86,7 @@ static bool
foldint(int op, Symbol *res, TINT l, TINT r)
{
TINT i;
+ Type *tp = res->type;
bool (*validate)(TINT, TINT, Type *tp);
switch (op) {
_AT_@ -99,7 +100,7 @@ foldint(int op, Symbol *res, TINT l, TINT r)
default: validate = NULL; break;
}
- if (validate && !(*validate)(l, r, res->type))
+ if (validate && !(*validate)(l, r, tp))
return 0;
switch (op) {
_AT_@ -123,6 +124,7 @@ foldint(int op, Symbol *res, TINT l, TINT r)
case ONE: i = l != r; break;
case ONEG: i = -l; break;
case OCPL: i = ~l; break;
+ default: return 0;
}
res->u.i = i;
return 1;
_AT_@ -155,6 +157,7 @@ folduint(int op, Symbol *res, TINT l, TINT r)
case OLE: i = l <= r; goto unsign;
case OEQ: i = l == r; goto unsign;
case ONE: i = l != r; goto unsign;
+ default: return 0;
}
sign:
_AT_@ -201,7 +204,7 @@ foldconst(int type, int op, Type *tp, Symbol *ls, Symbol *rs)
TUINT u;
TFLOAT f;
- aux.type = ls->type;
+ aux.type = tp;
switch (type) {
case INT:
i = (rs) ? rs->u.i : 0;
Received on Tue Sep 01 2015 - 20:10:55 CEST
This archive was generated by hypermail 2.3.0
: Tue Sep 01 2015 - 20:12:13 CEST