Templated struct as function parameter with partial calculated template specification puts interpreter into infinite recursion
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
Consider the following code
```Rust
struct Foo {}
// fully specified template parameters for type Foo.
fn works(x: Foo) {}
// Partial template specification of Foo, expecting V to be derived as U+1
fn does_not_work(x: Foo) {}
#[test]
fn works_test() {
works(Foo<3>{});
}
#[test]
fn does_not_work_test() {
// This results in a recursion, resuling in a segfault
does_not_work(Foo<3> {});
}
```
running this, will cause a segfault:
```
bazel-bin/xls/dslx/interpreter_main segfault.x
```
Turns out the segfault is due to a stack overflow. Some sort of inifinite recursion
```
(gdb) bt
#0 0x000055555704231f in xls::dslx::(anonymous namespace)::TypeRefUnwrapper::HandleTypeRefTypeAnnotation(xls::dslx::TypeRefTypeAnnotation const*) ()
#1 0x000055555703fcd7 in xls::dslx::GetStructOrProcRef(xls::dslx::TypeAnnotation const*, xls::dslx::ImportData const&, bool) ()
#2 0x0000555556f4db34 in xls::dslx::(anonymous namespace)::CanonicalizeTypeRefTypeAnnotation(xls::dslx::TypeRefTypeAnnotation const*, xls::dslx::ImportData&) ()
#3 0x0000555556f4d485 in absl::lts_20260526::Status absl::lts_20260526::internal_any_invocable::LocalInvoker(absl::lts_20260526::internal_any_invocable::TypeErasedState*, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type) ()
#4 0x0000555556f50590 in xls::dslx::(anonymous namespace)::ZipInternal(xls::dslx::(anonymous namespace)::ZipVisitor*, xls::dslx::AstNode const*, xls::dslx::AstNode const*) ()
#5 0x0000555556f50356 in xls::dslx::ZipAst(xls::dslx::AstNode const*, xls::dslx::AstNode const*, xls::dslx::AstNodeVisitor*, xls::dslx::AstNodeVisitor*, xls::dslx::ZipAstOptions) ()
#6 0x0000555556f4d507 in absl::lts_20260526::Status absl::lts_20260526::internal_any_invocable::LocalInvoker(absl::lts_20260526::internal_any_invocable::TypeErasedState*, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type) ()
#7 0x0000555556f50590 in xls::dslx::(anonymous namespace)::ZipInternal(xls::dslx::(anonymous namespace)::ZipVisitor*, xls::dslx::AstNode const*, xls::dslx::AstNode const*) ()
#8 0x0000555556f50356 in xls::dslx::ZipAst(xls::dslx::AstNode const*, xls::dslx::AstNode const*, xls::dslx::AstNodeVisitor*, xls::dslx::AstNodeVisitor*, xls::dslx::ZipAstOptions) ()
#9 0x0000555556f4d507 in absl::lts_20260526::Status absl::lts_20260526::internal_any_invocable::LocalInvoker(absl::lts_20260526::internal_any_invocable::TypeErasedState*, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type, absl::lts_20260526::internal_any_invocable::ForwardedParameter::type) ()
... and so on
```
Contributor guide
Assessment
This issue has not been assessed yet.