diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-03-22 10:47:05 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-03-24 08:43:00 +0100 |
| commit | 8cf47975a6532c9cb87e7c5dbfd462f5299a078b (patch) | |
| tree | cbd36a7fe2689279e579d50d18a991aeae29ddb1 /pkg | |
| parent | 2a504af1a3f752882c9027d64f2260424e91f1d6 (diff) | |
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).
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/compiler/types.go | 4 |
1 files changed, 3 insertions, 1 deletions
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)<<bitSize - 1) }, Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type { return &prog.ConstType{ |
