From 8cf47975a6532c9cb87e7c5dbfd462f5299a078b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 22 Mar 2020 10:47:05 +0100 Subject: pkg/compiler: truncate const values to their physical size We do similar truncation for values in the prog package (truncateToBitSize). Truncating them in the generated descriptions makes it possible to directly compare values (otherwise -1 and truncated -1 don't match). --- pkg/compiler/types.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 968b8fbc3..fce1153de 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -291,9 +291,11 @@ var typeConst = &typeDesc{ Args: []namedArg{{Name: "value", Type: typeArgInt}}, CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) { v := args[0].Value + bitSize := base.TypeBitSize() if constOverflowsBase(v, base) { - comp.error(args[0].Pos, "const val 0x%x does not fit into %v bits", v, base.TypeBitSize()) + comp.error(args[0].Pos, "const val 0x%x does not fit into %v bits", v, bitSize) } + args[0].Value = v & (uint64(1)<