{
Node *n;
Sym *s;
- Type *t;
+ Type *t, *tr;
long v;
Val val;
if(strcmp(s->name, "Sizeof") == 0) {
walktype(r, Erv);
- if(r->type == T)
+ tr = r->type;
+ if(r->op == OLITERAL && r->val.ctype == CTSTR)
+ tr = types[TSTRING];
+ if(tr == T)
goto no;
- v = r->type->width;
+ v = tr->width;
goto yes;
}
if(strcmp(s->name, "Offsetof") == 0) {
}
if(strcmp(s->name, "Alignof") == 0) {
walktype(r, Erv);
- if (r->type == T)
+ tr = r->type;
+ if(r->op == OLITERAL && r->val.ctype == CTSTR)
+ tr = types[TSTRING];
+ if(tr == T)
goto no;
+
// make struct { byte; T; }
t = typ(TSTRUCT);
t->type = typ(TFIELD);
t->type->type = types[TUINT8];
t->type->down = typ(TFIELD);
- t->type->down->type = r->type;
+ t->type->down->type = tr;
// compute struct widths
dowidth(t);
+
// the offset of T is its required alignment
v = t->type->down->width;
goto yes;