shithub: scc

Download patch

ref: 9fd36fb80508d28346e8767f86b1e6dc587993d5
parent: b9728db82bc35ed52a48fb538a9d4a40e251b32f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Mar 30 10:00:33 EDT 2022

cc2/qbe: Use correct return type in cast()

We don't have to do anything in qbe when we do cast that decrease
the size of a node, but we do have to update the type of the returned
node.

--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -222,8 +222,10 @@
 	s_isint = (ts->flags & INTF) != 0;
 
 	if (d_isint && s_isint) {
-		if (td->size <= ts->size)
+		if (td->size <= ts->size) {
+			np->type = *td;
 			return np;
+		}
 
 		assert(td->size == 4 || td->size == 8);
 		switch (ts->size) {
--- /dev/null
+++ b/tests/cc/execute/0204-cast.c
@@ -1,0 +1,17 @@
+int
+main(void)
+{
+	static char *p = "\xe2\x80\x9c";
+	unsigned n = 0;
+
+	for (; *p; p++) {
+		n <<= 1;
+		if ((unsigned char)*p >= ' ' && (unsigned char)*p != 0x7f)
+			n |= 1;
+	}
+
+	if (n != 7)
+		return 1;
+
+	return 0;
+}
--- a/tests/cc/execute/scc-tests.lst
+++ b/tests/cc/execute/scc-tests.lst
@@ -194,3 +194,4 @@
 0201-cpp.c [TODO]
 0202-variadic.c [TODO]
 0203-comment.c
+0204-cast.c