qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 496c069405cd79aed968f59dd5a5f92d1f96809f
parent 5e5e301e866e1eeb4523b9ecae6a2a327c019a08
Author: Michael Forney <mforney@mforney.org>
Date:   Sat, 19 Sep 2020 16:33:43 -0700

fold: zero-initialize padding bits of constants

Otherwise, if a constant is stored as a float and retrieved as an
int, the padding bits are uninitialized. This can result in the
generation of invalid assembly:

  Error: suffix or operands invalid for `cvtsi2ss'

Reported by Hiltjo Posthuma.

Diffstat:
Mfold.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fold.c b/fold.c @@ -459,6 +459,8 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr) if (cl->type != CBits || cr->type != CBits) err("invalid address operand for '%s'", optab[op].name); + *res = (Con){CBits}; + memset(&res->bits, 0, sizeof(res->bits)); if (w) { ld = cl->bits.d; rd = cr->bits.d; @@ -473,7 +475,8 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr) case Ocast: xd = ld; break; default: die("unreachable"); } - *res = (Con){CBits, .bits={.d=xd}, .flt=2}; + res->bits.d = xd; + res->flt = 2; } else { ls = cl->bits.s; rs = cr->bits.s; @@ -488,7 +491,8 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr) case Ocast: xs = ls; break; default: die("unreachable"); } - *res = (Con){CBits, .bits={.s=xs}, .flt=1}; + res->bits.s = xs; + res->flt = 1; } }