Skip to content

Commit

Permalink
Pointer fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Aug 3, 2024
1 parent f582537 commit 13b910f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
6 changes: 3 additions & 3 deletions compiler/ast/ssagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2261,11 +2261,11 @@ func (ast *Copy) SSA(block *ssa.Block, ctx *Codegen, gen *ssa.Generator) (
return nil, nil, ast.errf(ctx, ast.Src, "got multivalue %T", ast.Src)
}
src := v[0]
srcType := src.IndirectType()
if !srcType.Type.Array() {
src = src.Indirect(block, gen)
if !src.Type.Type.Array() {
return nil, nil, ast.errf(ctx, ast.Src, "got %v", src.Type)
}
if !dst.Type.ElementType.Equal(*srcType.ElementType) {
if !dst.Type.ElementType.Equal(*src.Type.ElementType) {
return nil, nil, ctx.Errorf(ast,
"arguments to copy have different element types: %s and %s",
dst.Type.ElementType, src.Type.ElementType)
Expand Down
29 changes: 29 additions & 0 deletions compiler/ssa/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,35 @@ func (v Value) IndirectType() types.Info {
return v.Type
}

// Indirect returns Value that v points to. If v is not a pointer,
// Indirect returns v.
func (v Value) Indirect(block *Block, gen *Generator) Value {
if v.Type.Type != types.TPtr {
return v
}

// Get container value.
b, ok := v.PtrInfo.Bindings.Get(v.PtrInfo.Name)
if !ok {
panic("Value.Indirect: could not find pointer target")
}
cv := b.Value(block, gen)

if v.PtrInfo.ContainerType.Type != types.TStruct {
return cv
}

// Get struct field value.
elType := *v.Type.ElementType
ev := gen.AnonVal(elType)
fromConst := gen.Constant(int64(v.PtrInfo.Offset), types.Undefined)
toConst := gen.Constant(int64(v.PtrInfo.Offset+elType.Bits),
types.Undefined)
block.AddInstr(NewSliceInstr(cv, fromConst, toConst, ev))

return ev
}

// ContainerType returs the pointer container type of the value. For
// non-pointer values, this returns the value type itself.
func (v Value) ContainerType() types.Info {
Expand Down
10 changes: 3 additions & 7 deletions pkg/crypto/ed25519/internal/edwards25519/ed25519.mpcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- go -*-
//
// Copyright (c) 2020-2023 Markku Rossi
// Copyright (c) 2020-2024 Markku Rossi
//
// Ed25519 signature algorithm in MPCL. This file is derived from the
// crypto/ed25519/internal/edwards25519 package of Go 1.16.9. The
Expand All @@ -24,9 +24,7 @@ type FieldElement [10]int32
var zero FieldElement

func FeZero(fe *FieldElement) {
for i := 0; i < len(fe); i++ {
fe[i] = zero[i]
}
copy(fe[:], zero[:])
}

func FeOne(fe *FieldElement) {
Expand Down Expand Up @@ -61,9 +59,7 @@ func FeSub(dst, a, b *FieldElement) {
}

func FeCopy(dst, src *FieldElement) {
for i := 0; i < len(dst); i++ {
dst[i] = src[i]
}
copy(dst[:], src[:])
}

// Replace (f,g) with (g,g) if b == 1;
Expand Down

0 comments on commit 13b910f

Please sign in to comment.