shithub: mc

Download patch

ref: e9a476ebae14c3d6a806bddc1b7514b60a846fc4
parent: d21cc40703f9e3fb86e590fce62ee0847fc6cfd8
author: Ori Bernstein <[email protected]>
date: Fri Dec 11 17:20:11 EST 2015

Fix code to disallow use before definition.

	At least in some cases.

--- a/6/main.c
+++ b/6/main.c
@@ -23,7 +23,7 @@
 Node *file;
 char debugopt[128];
 int writeasm;
-int extracheck;
+int extracheck = 1;
 int p9asm;
 char *outfile;
 char **incpaths;
@@ -164,7 +164,7 @@
 
 	outfile = NULL;
 
-	optinit(&ctx, "d:hSo:I:9G", argv, argc);
+	optinit(&ctx, "cd:hSo:I:9G", argv, argc);
 	asmsyntax = Defaultasm;
 	while (!optdone(&ctx)) {
 		switch (optnext(&ctx)) {
@@ -181,6 +181,7 @@
 			break;
 		case 'c':
 			extracheck = 1;
+			break;
 		case 'd':
 			while (ctx.optarg && *ctx.optarg)
 				debugopt[*ctx.optarg++ & 0x7f]++;
--- a/6/simp.c
+++ b/6/simp.c
@@ -963,6 +963,10 @@
 		t = lval(s, lhs);
 		u = rval(s, rhs, t);
 
+		/* hack: we're assigning to lhs, but blitting shit over doesn't
+		 * trigger that */
+		if (stacknode(lhs))
+			def(s, lhs);
 		/* if we stored the result into t, rval() should return that,
 		 * so we know our work is done. */
 		if (u == t) {
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -68,6 +68,7 @@
 	s = bigshli(mkbigint(1), max(0, -(e - p)))
 	mm = bigshli(mkbigint(1), max((e - p), 0))
 	mp = bigdup(mm)
+	u = mkbigint(0)
 
 	/* fixup: unequal gaps */
 	t = mkbigint(1)
--- a/lib/std/fmtfuncs.myr
+++ b/lib/std/fmtfuncs.myr
@@ -13,8 +13,12 @@
 	var bigint : bigint#
 	var bitset : bitset#
 
+	bigint = mkbigint(0)
+	bitset = mkbs()
 	fmtinstall(typeof(bigint), bigfmt, [][:])
 	fmtinstall(typeof(bitset), bsfmt, [][:])
+	bigfree(bigint)
+	bsfree(bitset)
 }
 
 const bigfmt = {sb, ap, opts
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -61,6 +61,7 @@
 	var chars
 	var c, h
 
+	chars = [][:]
 	while s.len != 0
 		(c, s) = std.striter(s)
 		chars = std.slpush(chars, c)
--- a/mbld/syssel.myr
+++ b/mbld/syssel.myr
@@ -152,7 +152,8 @@
 const word = {data
 	var c, split
 
-	c = std.decode(data[split:])
+	split = 0
+	c = std.decode(data[:])
 	while std.isalnum(c) || c == '.' || c == '_' || c == '$'
 		split += std.charlen(c)
 	;;
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -23,6 +23,8 @@
 		return;
 	if (exprop(n) == Ovar) {
 		did = n->expr.did;
+		if (decls[did]->decl.isconst)
+			return;
 		for (j = 0; j < r->ndefs[did]; j++) {
 			t = tybase(exprtype(n));
 			if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray || t->type == Tytuple)
@@ -33,7 +35,7 @@
 				continue;
 			def = nodes[r->defs[did][j]];
 			if (exprop(def) == Oundef)
-				fatal(n, "%s used before definition", namestr(n->expr.args[0]));
+				fatal(n, "%s used before definition [%d]", namestr(n->expr.args[0]), (int)did);
 		}
 	} else {
 		switch (exprop(n)) {
@@ -44,7 +46,7 @@
 			break;
 		case Oaddr:
 		case Oslice:
-			/* these don't actually look at the of args[0], so they're ok. */
+			/* these don't actually look at the value of args[0], so they're ok. */
 			for (i = 1; i < n->expr.nargs; i++)
 				checkundef(n->expr.args[i], r, reach, kill);
 			break;
@@ -127,5 +129,5 @@
 void check(Cfg *cfg)
 {
 	checkret(cfg);
-	if(0) checkreach(cfg);
+	checkreach(cfg);
 }
--- a/support/vim/ftdetect/myr.vim
+++ b/support/vim/ftdetect/myr.vim
@@ -1,3 +1,3 @@
 au BufRead,BufNewFile *.myr
-            \ set ft=myr |
-            \ set errorformat=%f:%l:\ %m,%D%f/%[a-z]%#...,%Dproject\ base\ %f:
+            \ setlocal ft=myr |
+            \ setlocal errorformat=%f:%l:\ %m,%D%f/%[a-z]%#...,%Dproject\ base\ %f: