diff --git a/cl/preload.go b/cl/preload.go index 0d0f9380c..9e94a867d 100644 --- a/cl/preload.go +++ b/cl/preload.go @@ -152,7 +152,21 @@ func (p *overloads) reorder() { if len(items) > 1 { sort.SliceStable(items, func(i, j int) bool { a, b := items[i].decl, items[j].decl + // NumArguments reports -1 for cursors that are not functions or + // methods (e.g. a class template and its partial specializations, + // which share one overload group under the same C/C++ name). Clamp + // to 0 so such cursors are treated as having no arguments: the + // argument-based ordering below is only meaningful for function + // overloads, and feeding -1 into the unsigned loop counter c.Uint(na) + // would otherwise wrap to ~4.3 billion iterations and hang the + // generator. See issue goplus/llcppg#894. na, nb := a.NumArguments(), b.NumArguments() + if na < 0 { + na = 0 + } + if nb < 0 { + nb = 0 + } if na != nb { return na < nb } diff --git a/tool/_testcpp/llvm-22.1.8-support/STLForwardCompat/out.go b/tool/_testcpp/llvm-22.1.8-support/STLForwardCompat/out.go index 007018fa4..f4b3bacf4 100644 --- a/tool/_testcpp/llvm-22.1.8-support/STLForwardCompat/out.go +++ b/tool/_testcpp/llvm-22.1.8-support/STLForwardCompat/out.go @@ -4,12 +4,12 @@ import "github.com/goplus/lib/c" const LLGoPackage = "link: -L$(llvm-config --libdir) -lLLVM; -lLLVM" +type RemoveCvref[T any] struct { +} +type TypeIdentity[T any] struct { +} type Identity struct { } type IdentityIsTransparent = c.Void type FromRangeT struct { } -type RemoveCvref[T any] struct { -} -type TypeIdentity[T any] struct { -} diff --git a/tool/gen_test.go b/tool/gen_test.go index 01a3d1a2b..ba77a40a8 100644 --- a/tool/gen_test.go +++ b/tool/gen_test.go @@ -318,7 +318,7 @@ func TestLLVM_Compiler(t *testing.T) { testFromDir(t, "Compiler", "./_testcpp", true, "system") } -func _TestLLVM_DenseMapInfo(t *testing.T) { +func TestLLVM_DenseMapInfo(t *testing.T) { testFromDir(t, "DenseMapInfo", "./_testcpp", true, "adt") } @@ -334,6 +334,6 @@ func TestLLVM_iterator_range(t *testing.T) { testFromDir(t, "iterator_range", "./_testcpp", true, "adt") } -func _TestLLVM_STLForwardCompat(t *testing.T) { +func TestLLVM_STLForwardCompat(t *testing.T) { testFromDir(t, "STLForwardCompat", "./_testcpp", true, "adt") }