Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@teqdruid
Copy link
Contributor

Builders don't always specify the block. If it doesn't, this function segfaults.

@teqdruid teqdruid added the HW Involving the `hw` dialect label Jul 11, 2025
@teqdruid
Copy link
Contributor Author

This was the root cause of a bug reported by a PyCDE user. In this case, it was triggered by the lower-seq-hlmem but it's been a problem for me in the past. I was able to fix it for this specific case with 2d75698, but that doesn't address the root cause.

Problem with this bug is that I don't know how to craft a test for it! How would I create a test for it?

@teqdruid teqdruid requested a review from Copilot July 11, 2025 05:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a guard in HWDialect::materializeConstant to check for a null block before dereferencing, preventing a potential segfault when no block is set.

  • Cache builder.getBlock() in a local variable and verify it’s non-null
  • Move the parent operation lookup and parameter expression handling inside the null check
Comments suppressed due to low confidence (1)

lib/Dialect/HW/HWDialect.cpp:105

  • Add a unit test for calling materializeConstant with a builder that has no block to ensure it returns nullptr instead of crashing.
  Block *block = builder.getBlock();

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, agree with copilot suggestion. For test probably you can create unittest under HW something like this https://github.com/llvm/circt/blob/2d75698c6396769afa084b80d133c4ad0532ed6d/unittests/Dialect/RTG/MaterializerTest.cpp.

@teqdruid
Copy link
Contributor Author

For test probably you can create unittest under HW something like this

I totally forgot we had C++ unit tests!

Builders don't always specify the block. If it doesn't, this function
segfaults.
@teqdruid teqdruid force-pushed the teqdruid/get-block branch from 0411559 to 4a9b49a Compare July 11, 2025 06:08
@teqdruid teqdruid marked this pull request as ready for review July 11, 2025 06:08
@teqdruid teqdruid requested a review from darthscsi as a code owner July 11, 2025 06:08
@teqdruid teqdruid merged commit b9004ca into main Jul 11, 2025
7 checks passed
@teqdruid teqdruid deleted the teqdruid/get-block branch July 11, 2025 06:24
@teqdruid
Copy link
Contributor Author

Thanks @uenoku !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

HW Involving the `hw` dialect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PyCDE] Segmentation Fault During Constant Struct Initialization in PyCDE

2 participants