llvm / llvm/circt

[FIRRTL] zero-width aggregate consumers crash or produce invalid IR

Open
#11,063 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

CIRCT mishandles legal consumers of zero-width aggregate values.

The following legal FIRRTL code crashes firtool:

FIRRTL version 4.0.0
circuit Top:
  module Child:
    output out: {nested: {zero: UInt<1>[0]}}
  public module Top:
    output size: UInt<32>
    inst child of Child
    node sizeNode = intrinsic(circt_sizeof : UInt<32>, child.out)
    connect size, sizeNode

Run with:

./bin/firtool --scalarize-internal-modules=true ./test.fir

LowerSignatures removes the child instance result because the aggregate has no fields. Its cleanup only handles connects and aggregate projections, so the intrinsic is treated as an unexpected user and the compiler aborts:

unexpected user of zero-width instance result
UNREACHABLE executed at lib/Dialect/FIRRTL/Transforms/LowerSignatures.cpp:419!

Relevant backtrace:

#7  eraseZeroWidthUsers(...)                         LowerSignatures.cpp:0:0
#8  lowerModuleBody(...)                             LowerSignatures.cpp:0:0
#9  mlir::detail::walk<mlir::ReverseIterator>(...)
#10 LowerSignaturesPass::runOnOperation(...)

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 in lib/Dialect/FIRRTL/Transforms/LowerSignatures.cpp, especially eraseZeroWidthUsers and lowerModuleBody, and reproduce the failure with the firtool command shown in the issue. Trace how the intrinsic user is handled when the instance result has no fields. Done means the legal FIRRTL example no longer crashes and does not produce invalid IR.

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
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.