diff --git a/ssa/type.go b/ssa/type.go index e9f3aab4f2..32260d41b5 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -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} diff --git a/test/go/recursive_pointer_type_test.go b/test/go/recursive_pointer_type_test.go new file mode 100644 index 0000000000..1b0f91082f --- /dev/null +++ b/test/go/recursive_pointer_type_test.go @@ -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) +} diff --git a/test/goroot/xfail.yaml b/test/goroot/xfail.yaml index a5a66d10b4..d28428e382 100644 --- a/test/goroot/xfail.yaml +++ b/test/goroot/xfail.yaml @@ -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 @@ -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 @@ -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 @@ -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