scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 127c1b7e3029959004d49aedcf3475342bbff623
parent 90d248506ca5feff59364a53296d173d320607d3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 30 Mar 2022 14:00:33 +0200

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.

Diffstat:
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 4+++-
Atests/cc/execute/0204-cast.c | 17+++++++++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -222,8 +222,10 @@ cast(Type *td, Node *np) 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) { diff --git a/tests/cc/execute/0204-cast.c b/tests/cc/execute/0204-cast.c @@ -0,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; +} diff --git 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