From 679482fc602445b9b2d37739e7b048e2d4913646 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 20 Nov 2020 14:02:37 -0800 Subject: [PATCH] [release-branch.go1.14] cmd/compile: sign extend constant folding properly MOVLconst must have a properly sign-extended auxint constant. The bit operations in these rules don't enforce that invariant. Fixes #42755 Change-Id: I729afcad18752d9b7739e49709020e3be7b3653e Reviewed-on: https://go-review.googlesource.com/c/go/+/272030 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: David Chase --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 6 +++--- src/cmd/compile/internal/ssa/rewriteAMD64.go | 12 ++++++------ test/fixedbugs/issue42753.go | 13 +++++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 test/fixedbugs/issue42753.go diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 2d662d5ae6..f819aefcfd 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1465,11 +1465,11 @@ (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) (BTSQconst [c] (MOVQconst [d])) -> (MOVQconst [d|(1< (MOVLconst [d|(1< (MOVLconst [int64(int32(d|(1< (MOVQconst [d&^(1< (MOVLconst [d&^(1< (MOVLconst [int64(int32(d&^(1< (MOVQconst [d^(1< (MOVLconst [d^(1< (MOVLconst [int64(int32(d^(1<