shithub: scc

Download patch

ref: a420fdf054d2a3b4bdbc79e1fc9b200463e2554a
parent: c7bfc2a9a69e9ac1953704608df3121081ef72db
author: Michael Forney <[email protected]>
date: Fri Feb 17 08:34:23 EST 2017

[cc2] Add missing * case to assign subop

This fixes *= assignment, which previously triggered a stack underflow.

Also, re-order the cases to match optbl.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -253,10 +253,11 @@
 	Node *np = newnode(u.op);
 
 	switch (subop = *++token) {
-	case '/':
-	case '%':
 	case '+':
 	case '-':
+	case '*':
+	case '%':
+	case '/':
 	case 'l':
 	case 'r':
 	case '&':
--- a/tests/execute/0037-assignop.c
+++ b/tests/execute/0037-assignop.c
@@ -9,9 +9,12 @@
 	x += 2;
 	if (x != 4)
 		return 1;
-	x -= 3;
-	if (x != 1)
+	x -= 1;
+	if (x != 3)
 		return 2;
+	x *= 2;
+	if (x != 6)
+		return 3;
 		
 	return 0;
 }