Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ssa/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ func (p Program) toType(raw types.Type) Type {
return &aType{p.tyVoidPtr(), typ, vkPtr}
}
case *types.Pointer:
elem := p.rawType(t.Elem())
return &aType{llvm.PointerType(elem.ll, 0), typ, vkPtr}
return &aType{p.tyVoidPtr(), typ, vkPtr}
case *types.Interface:
if t.Empty() {
return &aType{p.rtEface(), typ, vkEface}
Expand Down
88 changes: 88 additions & 0 deletions test/go/recursive_pointer_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gotest

import (
"os"
"path/filepath"
"testing"
)

const recursivePointerTypeProbe = `package main

type Link *Link
type Peano *Peano

func box(v Link) *Link {
p := new(Link)
*p = v
return p
}

func unbox(p *Link) Link {
return *p
}

func makePeano(n int) *Peano {
if n == 0 {
return nil
}
p := Peano(makePeano(n - 1))
return &p
}

var countArg Peano
var countResult int

func countPeano() {
if countArg == nil {
countResult = 0
return
}
countArg = *countArg
countPeano()
countResult++
}

func main() {
sentinel := Link(new(Link))
p := box(sentinel)
if unbox(p) != sentinel {
panic("recursive pointer type lost value")
}

countArg = makePeano(4096)
countPeano()
if countResult != 4096 {
panic("recursive Peano pointer count failed")
}
}
`

func TestRecursivePointerTypeBuilds(t *testing.T) {
dir := t.TempDir()
mainFile := filepath.Join(dir, "main.go")
if err := os.WriteFile(mainFile, []byte(recursivePointerTypeProbe), 0644); err != nil {
t.Fatal(err)
}

runGoCmd(t, dir, "run", mainFile)

root := findLLGoRoot(t)
t.Setenv("LLGO_ROOT", root)
runGoCmd(t, root, "run", "./cmd/llgo", "run", mainFile)
}
16 changes: 0 additions & 16 deletions test/goroot/xfail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2347,10 +2347,6 @@ xfails:
directive: run
case: mallocfin.go
reason: latest main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: peano.go
reason: latest main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: recover.go
Expand Down Expand Up @@ -3648,10 +3644,6 @@ xfails:
directive: run
case: fixedbugs/issue38496.go
reason: current main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: fixedbugs/issue4316.go
reason: current main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: fixedbugs/issue43835.go
Expand Down Expand Up @@ -3846,10 +3838,6 @@ xfails:
directive: run
case: fixedbugs/issue38496.go
reason: current main goroot run failure on linux/amd64
- platform: linux/amd64
directive: run
case: fixedbugs/issue4316.go
reason: current main goroot run failure on linux/amd64
- platform: linux/amd64
directive: run
case: fixedbugs/issue43835.go
Expand Down Expand Up @@ -3931,10 +3919,6 @@ xfails:
directive: run
case: nilptr.go
reason: current main goroot run failure on linux/amd64
- platform: linux/amd64
directive: run
case: peano.go
reason: current main goroot run failure on linux/amd64
- version: go1.24
platform: linux/amd64
directive: run
Expand Down
Loading