[SV][LowerSeqToSV] MLIR verifier/parer stack overflow in constructing deeply nested if
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 524
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 46
Description
IR lowered from following chisel has deeply-nested if operation with 2^14 depth. It causes stackoverflow in MLIR verifier (and parser if we use textual format of MLIR). Bytecode seems working.
```scala
//> using scala "2.13.10"
//> using lib "org.chipsalliance::chisel::5.0.0"
//> using plugin "org.chipsalliance:::chisel-plugin::5.0.0"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"
import chisel3._
import circt.stage.ChiselStage
import chisel3.util.PriorityEncoder
class Foo(width:Int) extends Module {
val input = IO(Input(UInt(math.pow(2, width).toInt.W)))
val out = IO(Output(UInt(width.W)))
val reg = RegInit(0.U(width.W))
out := reg
reg := PriorityEncoder(input)
}
object Main extends App {
println(
ChiselStage.emitCHIRRTL(new Foo(14))
)
}
```
[foo.mlirbc.zip](https://github.com/llvm/circt/files/11664629/foo.mlirbc.zip)
`circt-opt foo.mlirbc` or `mlir-opt --allow-unregistered-dialect foo.mlirbc` should reproduce the failure.
```
#743 0x0000000002ff45c3 mlir::LogicalResult::failed() const /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:44:33
#744 0x0000000002ff45c3 mlir::failed(mlir::LogicalResult) /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:72:58
#745 0x0000000002ff45c3 (anonymous namespace)::OperationVerifier::verifyDominanceOfContainedRegions(mlir::Operation&, mlir::DominanceInfo&) /scratch/hidetou/circt/llvm/mlir/lib/IR/Verifier.cpp:361:15
#746 0x0000000002ff45c3 mlir::LogicalResult::failed() const /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:44:33
#747 0x0000000002ff45c3 mlir::failed(mlir::LogicalResult) /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:72:58
#748 0x0000000002ff45c3 (anonymous namespace)::OperationVerifier::verifyDominanceOfContainedRegions(mlir::Operation&, mlir::DominanceInfo&) /scratch/hidetou/circt/llvm/mlir/lib/IR/Verifier.cpp:361:15
#749 0x0000000002ff45c3 mlir::LogicalResult::failed() const /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:44:33
#750 0x0000000002ff45c3 mlir::failed(mlir::LogicalResult) /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:72:58
#751 0x0000000002ff45c3 (anonymous namespace)::OperationVerifier::verifyDominanceOfContainedRegions(mlir::Operation&, mlir::DominanceInfo&) /scratch/hidetou/circt/llvm/mlir/lib/IR/Verifier.cpp:361:15
#752 0x0000000002ff45c3 mlir::LogicalResult::failed() const /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:44:33
#753 0x0000000002ff45c3 mlir::failed(mlir::LogicalResult) /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:72:58
#754 0x0000000002ff45c3 (anonymous namespace)::OperationVerifier::verifyDominanceOfContainedRegions(mlir::Operation&, mlir::DominanceInfo&) /scratch/hidetou/circt/llvm/mlir/lib/IR/Verifier.cpp:361:15
#755 0x0000000002ff45c3 mlir::LogicalResult::failed() const /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:44:33
#756 0x0000000002ff45c3 mlir::failed(mlir::LogicalResult) /scratch/hidetou/circt/llvm/mlir/include/mlir/Support/LogicalResult.h:72:58
#757 0x0000000002ff45c3 (anonymous namespace)::OperationVerifier::verifyDominanceOfContainedRegions(mlir::Operation&, mlir::DominanceInfo&) /scratch/hidetou/circt/llvm/mlir/lib/IR/Verifier.cpp:361:15
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure with the attached foo.mlirbc using circt-opt or mlir-opt --allow-unregistered-dialect. Inspect llvm/mlir/lib/IR/Verifier.cpp, especially OperationVerifier::verifyDominanceOfContainedRegions at line 361, and trace the corresponding textual parser path. Done means deeply nested if IR can be verified and parsed without overflowing the stack.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100