commit 6526c3052cb52d7a55d42444dcda3628be67a44f
parent 34e18c0eb51afa1b33b0db768be7ddef2a02ca63
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 18 Jun 2022 07:41:56 +0200
cc1: Detect decay'ed expressions in sizeof()
The current logic to avoid decay expressions used in sizeof
is too complex. It is better to just decay them and detect
the situation later and get the correct node and not the
decay'ed one.
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/cmd/cc/cc1/cc1.h b/src/cmd/cc/cc1/cc1.h
@@ -114,7 +114,8 @@ enum {
enum {
NLVAL = 1 << 0,
NCONST = 1 << 1,
- NEFFECT = 1 << 2
+ NEFFECT = 1 << 2,
+ NDECAY = 1 << 3,
};
/* lexer mode, compiler or preprocessor directive */
diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c
@@ -211,6 +211,8 @@ decay(Node *np)
new = node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL);
if (np->sym && np->sym->flags & (SGLOBAL|SLOCAL|SPRIVATE))
new->flags |= NCONST;
+ new->flags |= NDECAY;
+
return new;
}
@@ -733,10 +735,16 @@ static Node *unary(int);
static Type *
typeof(Node *np)
{
+ Node *new;
Type *tp;
if (np == NULL)
unexpected();
+ if ((np->flags & NDECAY) != 0) {
+ new = np->left;
+ free(np);
+ np = new;
+ }
tp = np->type;
freetree(np);
return tp;