ref: a901b27da57ae3df5a05f29b958104a55a10282b
parent: f441e1db75872457deb4aacf39500f3cc6185554
parent: 079e6ba6e4a218a64d593894050f546ca5cd3d34
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jun 16 12:43:52 EDT 2022
Merge remote-tracking branch 'origin/master'
--- a/src/cmd/cc/cc1/decl.c
+++ b/src/cmd/cc/cc1/decl.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@@ -48,14 +49,20 @@
static void
endfundcl(Type *tp, Symbol **pars)
{- if (tp->prop&TK_R && *pars)
- warn("parameter names (without types) in function declaration");/*
- * avoid non used warnings in prototypes
+ * If endfundcl is called from a type built from a typedef then
+ * we do not have any parameters because in that case we only
+ * care about the type.
*/
- while (*pars)
- (*pars++)->flags |= SUSED;
- popctx();
+ if (pars) {+ if ((tp->prop&TK_R) != 0 && *pars)
+ warn("parameter names (without types) in function declaration");+
+ /* avoid non used warnings in prototypes */
+ while (*pars)
+ (*pars++)->flags |= SUSED;
+ popctx();
+ }
}
static void
@@ -104,6 +111,13 @@
return 1;
}
+ /*
+ * We have a type derived from a function type. We don't care
+ * about the parameters because they were used only in the
+ * process of building a final type. Prototype arguments are
+ * discarded in funbody() because the final type of the decl
+ * is an actual function.
+ */
if (dcl->type->op == FTN)
endfundcl(dcl->type, dcl->pars);
dcl->pars = p->pars;
@@ -492,8 +506,16 @@
case TYPE:
case SCLASS:
case TYPEIDEN:
+ if (curctx < PARAMCTX) {+ assert(!pars);
+ errorp("typedef'ed function type cannot be instantiated");+ curctx = PARAMCTX;
+ pars = (Symbol *[]) {NULL};+ }
+
if (curctx != PARAMCTX)
errorp("nested function declaration");+
if (sym && sym->ns == NS_IDEN)
break;
default:
@@ -742,7 +764,7 @@
tp->ns = tpns++;
sym->type = tp;
tp->tag = sym;
- DBG("declared tag '%s' with ns = %d\n",+ DBG("DECL: declared tag '%s' with ns = %d\n",(sym->name) ? sym->name : "anonymous", tp->ns);
}
@@ -865,7 +887,6 @@
char *name = (sym->name) ? sym->name : anon;
Type *structp = dcl->parent, *tp = dcl->type;
TINT n = structp->n.elem;
- int err = 0;
if (accept(':')) {Node *np;
@@ -890,29 +911,31 @@
return sym;
}
- if (tp->op == FTN) {- errorp("invalid type '%s' in struct/union", name);- err = 1;
+ if (sym->flags & SDECLARED) {+ errorp("duplicated member '%s'", name);+ return sym;
}
- if (dcl->sclass) {- errorp("storage class in struct/union field '%s'", name);- err = 1;
+
+ if ((tp->prop & TDEFINED) == 0) {+ errorp("field '%s' has incomplete type", name);+ tp = inttype;
}
- if (!(tp->prop & TDEFINED)) {- error("field '%s' has incomplete type", name);- err = 1;
+ if (tp->op == FTN) {+ errorp("field '%s' declared as a function", name);+ tp = inttype;
}
- if (err)
- return sym;
+ if (dcl->sclass)
+ errorp("storage class in struct/union field '%s'", name);- if (sym->flags & SDECLARED)
- error("duplicated member '%s'", name);- sym->flags |= SFIELD|SDECLARED;
sym->type = tp;
+ sym->flags |= SFIELD|SDECLARED;
- if (n == NR_FIELDS)
- error("too many fields in struct/union");- DBG("New field '%s' in namespace %d\n", name, structp->ns);+ if (n == NR_FIELDS) {+ errorp("too many fields in struct/union");+ return sym;
+ }
+
+ DBG("DECL: New field '%s' in namespace %d\n", name, structp->ns);structp->p.fields = xrealloc(structp->p.fields, ++n * sizeof(*sym));
structp->p.fields[n-1] = sym;
structp->n.elem = n;
@@ -934,6 +957,7 @@
do {dcl.type = base;
+ dcl.pars = NULL;
stack.nr_types = stack.nr = 0;
stack.tpars = dcl.buftpars;
stack.pars = dcl.bufpars;
--- a/src/cmd/cc/cc1/init.c
+++ b/src/cmd/cc/cc1/init.c
@@ -209,8 +209,8 @@
ip->max = ip->pos+1;
}
-Node *
-initlist(Type *tp)
+static Node *
+initlist_helper(Type *tp)
{Init in;
Node *np;
@@ -217,11 +217,7 @@
Type *curtp;
int braces, scalar, toomany, outbound;
TINT nelem = tp->n.elem;
- static int depth;
- if (depth == NR_SUBTYPE)
- error("too many nested initializers");- ++depth;
init(&in);
braces = scalar = toomany = 0;
@@ -316,6 +312,22 @@
}
return mkcompound(&in, tp);
+}
+
+Node *
+initlist(Type *tp)
+{+ Node *np;
+ static int depth;
+
+ if (depth == NR_SUBTYPE)
+ error("too many nested initializers");+
+ ++depth;
+ np = initlist_helper(tp);
+ --depth;
+
+ return np;
}
static void
--- a/src/cmd/cc/cc1/lex.c
+++ b/src/cmd/cc/cc1/lex.c
@@ -52,7 +52,7 @@
addinput(int type, void *arg, int fail)
{FILE *fp;
- char *extp, *fname, *buffer, *infile;;
+ char *extp, *fname, *buffer, *infile;
int infileln;
Macro *mp;
Symbol *sym;
--- a/src/libc/stdio/_fpopen.c
+++ b/src/libc/stdio/_fpopen.c
@@ -12,7 +12,7 @@
const char *restrict mode,
FILE * restrict fp)
{- int i, flags, fd, rw, bin, rights;;
+ int i, flags, fd, rw, bin, rights;
flags = rw = bin = 0;
rights = 0666;
--- /dev/null
+++ b/tests/cc/execute/0206-initializer.c
@@ -1,0 +1,171 @@
+static int alpha3[][2] = {+ { 0x00D6, 0x00D8 },+ { 0x00F6, 0x00F8 },+ { 0x02EC, 0x02EE },+ { 0x0374, 0x0376 },+ { 0x037D, 0x037F },+ { 0x0386, 0x0388 },+ { 0x038A, 0x038E },+ { 0x03A1, 0x03A3 },+ { 0x03F5, 0x03F7 },+ { 0x052F, 0x0531 },+ { 0x066F, 0x0671 },+ { 0x06D3, 0x06D5 },+ { 0x0710, 0x0712 },+ { 0x09A8, 0x09AA },+ { 0x09B0, 0x09B2 },+ { 0x09DD, 0x09DF },+ { 0x0A28, 0x0A2A },+ { 0x0A30, 0x0A32 },+ { 0x0A33, 0x0A35 },+ { 0x0A36, 0x0A38 },+ { 0x0A5C, 0x0A5E },+ { 0x0A8D, 0x0A8F },+ { 0x0A91, 0x0A93 },+ { 0x0AA8, 0x0AAA },+ { 0x0AB0, 0x0AB2 },+ { 0x0AB3, 0x0AB5 },+ { 0x0B28, 0x0B2A },+ { 0x0B30, 0x0B32 },+ { 0x0B33, 0x0B35 },+ { 0x0B5D, 0x0B5F },+ { 0x0B83, 0x0B85 },+ { 0x0B90, 0x0B92 },+ { 0x0B9A, 0x0B9E },+ { 0x0C0C, 0x0C0E },+ { 0x0C10, 0x0C12 },+ { 0x0C28, 0x0C2A },+ { 0x0C8C, 0x0C8E },+ { 0x0C90, 0x0C92 },+ { 0x0CA8, 0x0CAA },+ { 0x0CB3, 0x0CB5 },+ { 0x0CDE, 0x0CE0 },+ { 0x0D0C, 0x0D0E },+ { 0x0D10, 0x0D12 },+ { 0x0DB1, 0x0DB3 },+ { 0x0DBB, 0x0DBD },+ { 0x0E30, 0x0E32 },+ { 0x0E82, 0x0E84 },+ { 0x0E88, 0x0E8A },+ { 0x0E97, 0x0E99 },+ { 0x0E9F, 0x0EA1 },+ { 0x0EA3, 0x0EA7 },+ { 0x0EAB, 0x0EAD },+ { 0x0EB0, 0x0EB2 },+ { 0x0EC4, 0x0EC6 },+ { 0x0F47, 0x0F49 },+ { 0x10C5, 0x10C7 },+ { 0x10FA, 0x10FC },+ { 0x1248, 0x124A },+ { 0x1256, 0x125A },+ { 0x1288, 0x128A },+ { 0x12B0, 0x12B2 },+ { 0x12BE, 0x12C2 },+ { 0x12D6, 0x12D8 },+ { 0x1310, 0x1312 },+ { 0x167F, 0x1681 },+ { 0x170C, 0x170E },+ { 0x176C, 0x176E },+ { 0x18A8, 0x18AA },+ { 0x1CEC, 0x1CEE },+ { 0x1F57, 0x1F5F },+ { 0x1FB4, 0x1FB6 },+ { 0x1FBC, 0x1FBE },+ { 0x1FC4, 0x1FC6 },+ { 0x1FF4, 0x1FF6 },+ { 0x2113, 0x2115 },+ { 0x2124, 0x212A },+ { 0x212D, 0x212F },+ { 0x2C2E, 0x2C30 },+ { 0x2C5E, 0x2C60 },+ { 0x2D25, 0x2D27 },+ { 0x2DA6, 0x2DA8 },+ { 0x2DAE, 0x2DB0 },+ { 0x2DB6, 0x2DB8 },+ { 0x2DBE, 0x2DC0 },+ { 0x2DC6, 0x2DC8 },+ { 0x2DCE, 0x2DD0 },+ { 0x2DD6, 0x2DD8 },+ { 0x309F, 0x30A1 },+ { 0x30FA, 0x30FC },+ { 0xA78E, 0xA790 },+ { 0xA801, 0xA803 },+ { 0xA805, 0xA807 },+ { 0xA80A, 0xA80C },+ { 0xA9E4, 0xA9E6 },+ { 0xA9FE, 0xAA00 },+ { 0xAA42, 0xAA44 },+ { 0xAAAF, 0xAAB1 },+ { 0xAAC0, 0xAAC2 },+ { 0xAB26, 0xAB28 },+ { 0xAB2E, 0xAB30 },+ { 0xAB5A, 0xAB5C },+ { 0xFB1D, 0xFB1F },+ { 0xFB28, 0xFB2A },+ { 0xFB36, 0xFB38 },+ { 0xFB3C, 0xFB40 },+ { 0xFB41, 0xFB43 },+ { 0xFB44, 0xFB46 },+ { 0xFE74, 0xFE76 },+ { 0x1000B, 0x1000D },+ { 0x10026, 0x10028 },+ { 0x1003A, 0x1003C },+ { 0x1003D, 0x1003F },+ { 0x10340, 0x10342 },+ { 0x10808, 0x1080A },+ { 0x10835, 0x10837 },+ { 0x10A13, 0x10A15 },+ { 0x10A17, 0x10A19 },+ { 0x10AC7, 0x10AC9 },+ { 0x11211, 0x11213 },+ { 0x11328, 0x1132A },+ { 0x11330, 0x11332 },+ { 0x11333, 0x11335 },+ { 0x114C5, 0x114C7 },+ { 0x1D454, 0x1D456 },+ { 0x1D49C, 0x1D49E },+ { 0x1D4AC, 0x1D4AE },+ { 0x1D4B9, 0x1D4BD },+ { 0x1D4C3, 0x1D4C5 },+ { 0x1D505, 0x1D507 },+ { 0x1D514, 0x1D516 },+ { 0x1D51C, 0x1D51E },+ { 0x1D539, 0x1D53B },+ { 0x1D53E, 0x1D540 },+ { 0x1D544, 0x1D546 },+ { 0x1D550, 0x1D552 },+ { 0x1D6C0, 0x1D6C2 },+ { 0x1D6DA, 0x1D6DC },+ { 0x1D6FA, 0x1D6FC },+ { 0x1D714, 0x1D716 },+ { 0x1D734, 0x1D736 },+ { 0x1D74E, 0x1D750 },+ { 0x1D76E, 0x1D770 },+ { 0x1D788, 0x1D78A },+ { 0x1D7A8, 0x1D7AA },+ { 0x1D7C2, 0x1D7C4 },+ { 0x1EE03, 0x1EE05 },+ { 0x1EE1F, 0x1EE21 },+ { 0x1EE22, 0x1EE24 },+ { 0x1EE27, 0x1EE29 },+ { 0x1EE32, 0x1EE34 },+ { 0x1EE37, 0x1EE3B },+ { 0x1EE47, 0x1EE4D },+ { 0x1EE4F, 0x1EE51 },+ { 0x1EE52, 0x1EE54 },+ { 0x1EE57, 0x1EE61 },+ { 0x1EE62, 0x1EE64 },+ { 0x1EE6A, 0x1EE6C },+ { 0x1EE72, 0x1EE74 },+ { 0x1EE77, 0x1EE79 },+ { 0x1EE7C, 0x1EE80 },+ { 0x1EE89, 0x1EE8B },+ { 0x1EEA3, 0x1EEA5 },+ { 0x1EEA9, 0x1EEAB },+};
+
+int
+main()
+{+ return alpha3 == 0;
+}
--- /dev/null
+++ b/tests/cc/execute/0207-structcb.c
@@ -1,0 +1,13 @@
+typedef int (cookie_seek_function_t)(void);
+
+typedef struct _IO_cookie_io_functions_t {+ cookie_seek_function_t *seek;
+} cookie_io_functions_t;
+
+cookie_seek_function_t seek;
+
+int
+main(void)
+{+ return 0;
+}
--- a/tests/cc/execute/scc-tests.lst
+++ b/tests/cc/execute/scc-tests.lst
@@ -196,3 +196,5 @@
0203-comment.c
0204-cast.c
0205-cpparg.c
+0206-initializer.c
+0207-structcb.c
--
⑨