llvm / llvm/circt

[PrepareForEmission] Crash when inout operations are passed to instance ports

Open
#4,036 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

```mlir
hw.module @TopXMRAsserts(%I: !hw.inout) -> () {}
hw.module @Top() -> () {
%I = sv.wire : !hw.inout
hw.instance "TopXMRAsserts_inst0" sym @Top.TopXMRAsserts_inst0 @TopXMRAsserts(I: %I: !hw.inout) -> () {doNotPrint = 1}
}
sv.bind #hw.innerNameRef<@Top::@Top.TopXMRAsserts_inst0>
```
`circt-opt -export-verilog`:
```
circt-opt: /home/uenoku/dev/circt/llvm/llvm/../mlir/include/mlir/IR/StorageUniquerSupport.h:153: static ConcreteT mlir::detail::StorageUserBase::get(mlir::MLIRContext *, Args...) [ConcreteT = circt::hw::InOutType, BaseT = mlir::Type, StorageT = circt::hw::detail::InOutTypeStorage, UniquerT = mlir::detail::TypeUniquer, Traits = <>, Args = ]: Assertion `succeeded(ConcreteT::verify(getDefaultDiagnosticEmitFn(ctx), args...))' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
#0 0x000055ccf68fee23 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/uenoku/dev/circt/llvm/llvm/lib/Support/Unix/Signals.inc:569:13
#1 0x000055ccf68fd0e0 llvm::sys::RunSignalHandlers() /home/uenoku/dev/circt/llvm/llvm/lib/Support/Signals.cpp:104:18
#2 0x000055ccf68ff47a SignalHandler(int) /home/uenoku/dev/circt/llvm/llvm/lib/Support/Unix/Signals.inc:407:1
#3 0x00007f04f0242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f04f0296a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f04f0296a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f04f0296a7c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f04f0242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f04f02287f3 abort ./stdlib/abort.c:81:7
#9 0x00007f04f022871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f04f0239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000055ccf6eb5897 (./bin/circt-opt+0xb1b897)
#12 0x000055ccf6fd56e8 circt::sv::WireOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Type, mlir::StringAttr, mlir::StringAttr) /home/uenoku/dev/circt/lib/Dialect/SV/SVOps.cpp:1296:21
#13 0x000055ccf6ffd651 circt::sv::WireOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Type, llvm::StringRef) /home/uenoku/dev/circt/build/tools/circt/include/circt/Dialect/SV/SV.cpp.inc:15061:7
#14 0x000055ccf6a68d51 circt::sv::WireOp mlir::OpBuilder::create&>(mlir::Location, mlir::Type&&, llvm::SmallString<32u>&) /home/uenoku/dev/circt/llvm/llvm/../mlir/include/mlir/IR/Builders.h:460:16
#15 0x000055ccf6a658ac spillWiresForInstanceInputs(circt::hw::InstanceOp) /home/uenoku/dev/circt/lib/Conversion/ExportVerilog/PrepareForEmission.cpp:103:28
#16 0x000055ccf6a658ac legalizeHWModule(mlir::Block&, circt::LoweringOptions const&) /home/uenoku/dev/circt/lib/Conversion/ExportVerilog/PrepareForEmission.cpp:735:9
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer and run `circt-opt -export-verilog` to confirm the crash. Read `lib/Conversion/ExportVerilog/PrepareForEmission.cpp`, especially `spillWiresForInstanceInputs` and `legalizeHWModule`, along with the `sv::WireOp::build` stack entry; done means the inout instance-port input is handled without the assertion failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.