google / google/xls

DSLX: bug - SIGSEGV in IR generation when token is returned in a tuple

Open
#1,035 4 comments 0 reactions 0 assignees View on GitHub
bug dslx
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

Consider the following code:
```
pub proc foo {
init {()}
config() {()}

next(tok: token, state: ()) {
let tok = if true {
tok
} else {
tok
};
()
}
}
```

Trying to make IR out of it results in the following, which I presume is expected:
```
$ ir_converter_main ...

F0619 18:16:20.305308 1718188 ir_converter_main.cc:163] Check failed: ::absl::OkStatus() == (status) (OK vs. INVALID_ARGUMENT: Could not build IR: Expected sel.5 to not contain a token in its type; type is token
File: 0, Line: 20, Col: 18
Stack Trace:
0x5650217e5732: xls::BuilderBase::SetError()
0x5650217e5af7: xls::BuilderBase::CreateBValue()
0x5650217e8846: xls::BuilderBase::Select()
0x5650217e8978: xls::BuilderBase::Select()
```

---

Now change the code as follows:
```
pub proc foo {
init {()}
config() {()}

next(tok: token, state: ()) {
let (a, tok) = if true {
(false, tok)
} else {
(true, tok)
};
()
}
}
```

Trying to run IR converter results in a silent segmentation fault. To figure out what happens the user must enable VLOG, scroll up and take a note of that SetError:
```
I0619 18:20:12.926616 1718441 verifier.cc:2014] Verifying node: sel.9: (bits[1], token) = sel(literal.4, cases=[tuple.8, tuple.6], id=9, pos=[(0,37,23)])
I0619 18:20:12.926625 1718441 function_builder.cc:109] BuilderBase::SetError; msg: Expected sel.9 to not contain a token in its type; type is (bits[1], token); loc: [(0,37,23)]
I0619 18:20:12.932035 1718441 function_converter.cc:370] Define node 'if true { (false, tok) } else { (true, tok) }' (Conditional) to be (nil) @ xls/modules/dbe/encoder_lz4.x:38:24-42:10
I0619 18:20:12.932047 1718441 function_converter.cc:419] Setting node 'if true { (false, tok) } else { (true, tok) }' (0x5562c8ed89f0) to IR value (nil).
I0619 18:20:12.932051 1718441 function_converter.cc:408] Using node 'if true { (false, tok) } else { (true, tok) }' (0x5562c8ed89f0) as IR value (nil).
I0619 18:20:12.932054 1718441 function_converter.cc:344] Aliased node 'let (a, tok) = if true { (false, tok) } else { (true, tok) };' (Let) to be same as 'if true { (false, tok) } else { (true, tok) }' (Conditional): (nil)
I0619 18:20:12.932059 1718441 function_converter.cc:641] Walking level 1 index 0: `a`
[1] 1718441 segmentation fault (core dumped) bazel-out/k8-opt-exec-2B5CBBC6/bin/xls/dslx/ir_convert/ir_converter_main
```

While doing such things with `token` may be forbidden for now, XLS should report it more gracefully.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.