summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2022-02-23 10:33:16 -0500
committerQuentin Carbonneaux <quentin@c9x.me>2022-02-24 12:56:30 +0100
commite7c13e8d0191d9e8987af42a8561fceba0f6c2f1 (patch)
treee42ae1e30678ac21f4d0e20f3bda39672aa0e1c8
parent4e93eeaa3b63b6ae50954a29662cc3ea6be48b23 (diff)
downloadroux-e7c13e8d0191d9e8987af42a8561fceba0f6c2f1.tar.gz
fix folding of shifts of word operand by >32
-rw-r--r--fold.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/fold.c b/fold.c
index 5d3c83c..58a7c4f 100644
--- a/fold.c
+++ b/fold.c
@@ -377,9 +377,9 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
 	case Oand:  x = l.u & r.u; break;
 	case Oor:   x = l.u | r.u; break;
 	case Oxor:  x = l.u ^ r.u; break;
-	case Osar:  x = (w ? l.s : (int32_t)l.s) >> (r.u & 63); break;
-	case Oshr:  x = (w ? l.u : (uint32_t)l.u) >> (r.u & 63); break;
-	case Oshl:  x = l.u << (r.u & 63); break;
+	case Osar:  x = (w ? l.s : (int32_t)l.s) >> (r.u & (31|w<<5)); break;
+	case Oshr:  x = (w ? l.u : (uint32_t)l.u) >> (r.u & (31|w<<5)); break;
+	case Oshl:  x = l.u << (r.u & (31|w<<5)); break;
 	case Oextsb: x = (int8_t)l.u;   break;
 	case Oextub: x = (uint8_t)l.u;  break;
 	case Oextsh: x = (int16_t)l.u;  break;