ref: 6526c3052cb52d7a55d42444dcda3628be67a44f
parent: 34e18c0eb51afa1b33b0db768be7ddef2a02ca63
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Jun 18 03:41:56 EDT 2022
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.
--- a/src/cmd/cc/cc1/cc1.h
+++ b/src/cmd/cc/cc1/cc1.h
@@ -114,7 +114,8 @@
enum {
NLVAL = 1 << 0,
NCONST = 1 << 1,
- NEFFECT = 1 << 2
+ NEFFECT = 1 << 2,
+ NDECAY = 1 << 3,
};
/* lexer mode, compiler or preprocessor directive */
--- a/src/cmd/cc/cc1/expr.c
+++ b/src/cmd/cc/cc1/expr.c
@@ -211,6 +211,8 @@
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 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;