llvm / llvm/circt

[FIRRTL] Crash with fstring type on port

Open
#8,382 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

fstring type would never be on port from the current fir parser but it crashes at LowerToHW:

```mlir
firrtl.circuit "Printf"{
// CHECK-LABEL: module Printf
firrtl.module @Printf(in %clock: !firrtl.fstring) attributes {convention = #firrtl} {
}
}
```

```
$ firtool bar.mlir

firtool: /scratch/hidetou/circt/lib/Conversion/FIRRTLToHW/LowerToHW.cpp:2562: llvm::LogicalResult (anonymous namespace)::FIRRTLLowering::setLowering(mlir::Value, mlir::Value): Assertion `(!result || !type_isa(result.getType())) && "Lowering didn't turn a FIRRTL value into a non-FIRRTL value"' failed.
PLEASE submit a bug report to https://github.com/llvm/circt and include the crash backtrace.
Stack dump:
0. Program arguments: ./build/bin/firtool bar.mlir
#0 0x00000000007ceb97 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /scratch/hidetou/circt/llvm/llvm/lib/Support/Unix/Signals.inc:804:13
#1 0x00000000007ccad0 llvm::sys::RunSignalHandlers() /scratch/hidetou/circt/llvm/llvm/lib/Support/Signals.cpp:106:18
#2 0x00000000007cf4aa SignalHandler(int, siginfo_t*, void*) /scratch/hidetou/circt/llvm/llvm/lib/Support/Unix/Signals.inc:0:3
#3 0x00007f083c2b1cf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
#4 0x00007f083b36aacf raise (/lib64/libc.so.6+0x4eacf)
#5 0x00007f083b33dea5 abort (/lib64/libc.so.6+0x21ea5)
#6 0x00007f083b33dd79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)
#7 0x00007f083b363426 (/lib64/libc.so.6+0x47426)
#8 0x0000000000d2176a decltype(auto) llvm::dyn_cast(mlir::Type const&) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/Casting.h:650:3
#9 0x0000000000d2176a decltype(auto) llvm::detail::TypeSwitchBase, mlir::Type>::castValue(mlir::Type const&) /scratch/hidetou/circt/llvm/llvm/include/llvm/ADT/TypeSwitch.h:67:12
#10 0x0000000000d2176a llvm::TypeSwitch& llvm::TypeSwitch::Case(circt::firrtl::getBaseType(mlir::Type)::'lambda0'(auto)&&) /scratch/hidetou/circt/llvm/llvm/include/llvm/ADT/TypeSwitch.h:101:26
#11 0x0000000000d2176a circt::firrtl::getBaseType(mlir::Type) /scratch/hidetou/circt/include/circt/Dialect/FIRRTL/FIRRTLUtils.h:225:8
#12 0x0000000000d2176a (anonymous namespace)::FIRRTLLowering::setLowering(mlir::Value, mlir::Value) /scratch/hidetou/circt/lib/Conversion/FIRRTLToHW/LowerToHW.cpp:2565:21
#13 0x0000000000d1ee1f llvm::LogicalResult::failed() const /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:43:43
#14 0x0000000000d1ee1f llvm::failed(llvm::LogicalResult) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:71:58
#15 0x0000000000d1ee1f (anonymous namespace)::FIRRTLLowering::run() /scratch/hidetou/circt/lib/Conversion/FIRRTLToHW/LowerToHW.cpp:1985:9
#16 0x0000000000d1ee1f (anonymous namespace)::FIRRTLModuleLowering::lowerModuleOperations(circt::hw::HWModuleOp, (anonymous namespace)::CircuitLoweringState&) /scratch/hidetou/circt/lib/Conversion/FIRRTLToHW/LowerToHW.cpp:1977:48
#17 0x0000000000d152a8 llvm::LogicalResult::failed() const /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:43:43
#18 0x0000000000d152a8 llvm::failed(llvm::LogicalResult) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:71:58
#19 0x0000000000d152a8 llvm::LogicalResult mlir::failableParallelForEach, (anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10>(mlir::MLIRContext*, llvm::detail::SafeIntIterator, llvm::detail::SafeIntIterator, (anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10&&) /scratch/hidetou/circt/llvm/llvm/../mlir/include/mlir/IR/Threading.h:46:11
#20 0x0000000000d152a8 llvm::LogicalResult mlir::failableParallelForEach, (anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10>(mlir::MLIRContext*, llvm::iota_range&&, (anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10&&) /scratch/hidetou/circt/llvm/llvm/../mlir/include/mlir/IR/Threading.h:92:10
#21 0x0000000000d152a8 llvm::LogicalResult mlir::failableParallelForEachN<(anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10>(mlir::MLIRContext*, unsigned long, unsigned long, (anonymous namespace)::FIRRTLModuleLowering::runOnOperation()::$_10&&) /scratch/hidetou/circt/llvm/llvm/../mlir/include/mlir/IR/Threading.h:107:10
#22 0x0000000000d152a8 (anonymous namespace)::FIRRTLModuleLowering::runOnOperation() /scratch/hidetou/circt/lib/Conversion/FIRRTLToHW/LowerToHW.cpp:753:17
#23 0x000000000148cff9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /scratch/hidetou/circt/llvm/mlir/lib/Pass/Pass.cpp:0:17
#24 0x000000000148cff9 void llvm::function_ref::callback_fn(long) /scratch/hidetou/circt/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#25 0x000000000148cff9 llvm::function_ref::operator()() const /scratch/hidetou/circt/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#26 0x000000000148cff9 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pass&) /scratch/hidetou/circt/llvm/mlir/include/mlir/IR/MLIRContext.h:288:7
#27 0x000000000148cff9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /scratch/hidetou/circt/llvm/mlir/lib/Pass/Pass.cpp:520:21
#28 0x000000000148fdbf llvm::LogicalResult::failed() const /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:43:43
#29 0x000000000148fdbf llvm::failed(llvm::LogicalResult) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:71:58
#30 0x000000000148fdbf mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /scratch/hidetou/circt/llvm/mlir/lib/Pass/Pass.cpp:592:9
#31 0x000000000148fdbf mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /scratch/hidetou/circt/llvm/mlir/lib/Pass/Pass.cpp:905:10
#32 0x000000000148fdbf mlir::PassManager::run(mlir::Operation*) /scratch/hidetou/circt/llvm/mlir/lib/Pass/Pass.cpp:885:60
#33 0x0000000000758686 llvm::LogicalResult::failed() const /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:43:43
#34 0x0000000000758686 llvm::failed(llvm::LogicalResult) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:71:58
#35 0x0000000000758686 processBuffer(mlir::MLIRContext&, circt::firtool::FirtoolOptions&, mlir::TimingScope&, llvm::SourceMgr&, std::optional>>&) /scratch/hidetou/circt/tools/firtool/firtool.cpp:561:7
#36 0x00000000007572fb processInputSplit(mlir::MLIRContext&, circt::firtool::FirtoolOptions&, mlir::TimingScope&, std::unique_ptr>, std::optional>>&) /scratch/hidetou/circt/tools/firtool/firtool.cpp:619:12
#37 0x0000000000752e60 processInput(mlir::MLIRContext&, circt::firtool::FirtoolOptions&, mlir::TimingScope&, std::unique_ptr>, std::optional>>&) /scratch/hidetou/circt/tools/firtool/firtool.cpp:635:12
#38 0x0000000000752e60 executeFirtool(mlir::MLIRContext&, circt::firtool::FirtoolOptions&) /scratch/hidetou/circt/tools/firtool/firtool.cpp:727:14
#39 0x0000000000751288 llvm::LogicalResult::failed() const /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:43:43
#40 0x0000000000751288 llvm::failed(llvm::LogicalResult) /scratch/hidetou/circt/llvm/llvm/include/llvm/Support/LogicalResult.h:71:58
#41 0x0000000000751288 main /scratch/hidetou/circt/tools/firtool/firtool.cpp:822:8
#42 0x00007f083b356d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#43 0x000000000075030e _start (./build/bin/firtool+0x75030e)
Aborted
```

Ideally IR verifier should catch this

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied MLIR reproducer with firtool and inspect the failure in lib/Conversion/FIRRTLToHW/LowerToHW.cpp around setLowering. Then trace the FIRRTL IR verification path for module ports of type !firrtl.fstring. Done means the invalid port is rejected by the verifier with a diagnostic instead of reaching the lowering assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.