This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 176
Fix issue where inlined cvt could cause crash #2124
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* These PrimOps emit either {..., a0, ...} or a0 so they never need parentheses | ||
*/ | ||
private val neverParens: PrimOp => Boolean = | ||
Set(Shl, Cat, Cvt, AsUInt, AsSInt, AsClock, AsAsyncReset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding Pad
? I doubt this case gets hit in any code given the current inlining status, but it looks like it might be possible to get ({a0})
if you got the right tree in the emitter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call
Due to inlining of Boolean expressions, the following circuit is handled directly by the VerilogEmitter: input a: UInt<4> input b: SInt<1> output o: UInt<5> o <= dshl(a, asUInt(cvt(b))) Priot to this change, this could crash due to mishandling of cvt in the logic to inject parentheses based on Verilog precedence rules. This is a corner case, but similar bugs would drop up if we open up the VerilogEmitter to more expression inlining.
albert-magyar
approved these changes
Mar 16, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mergify bot
pushed a commit
that referenced
this pull request
Mar 16, 2021
Due to inlining of Boolean expressions, the following circuit is handled directly by the VerilogEmitter: input a: UInt<4> input b: SInt<1> output o: UInt<5> o <= dshl(a, asUInt(cvt(b))) Priot to this change, this could crash due to mishandling of cvt in the logic to inject parentheses based on Verilog precedence rules. This is a corner case, but similar bugs would drop up if we open up the VerilogEmitter to more expression inlining. (cherry picked from commit 94d1bee)
mergify
bot
added
the
Backported
This PR has been backported to marked stable branch
label
Mar 16, 2021
mergify bot
added a commit
that referenced
this pull request
Mar 16, 2021
Due to inlining of Boolean expressions, the following circuit is handled directly by the VerilogEmitter: input a: UInt<4> input b: SInt<1> output o: UInt<5> o <= dshl(a, asUInt(cvt(b))) Priot to this change, this could crash due to mishandling of cvt in the logic to inject parentheses based on Verilog precedence rules. This is a corner case, but similar bugs would drop up if we open up the VerilogEmitter to more expression inlining. (cherry picked from commit 94d1bee) Co-authored-by: Jack Koenig <koenig@sifive.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to inlining of Boolean expressions, the following circuit is handled
directly by the VerilogEmitter:
Priot to this change, this could crash due to mishandling of cvt in the
logic to inject parentheses based on Verilog precedence rules.
This is a corner case, but similar bugs would drop up if we open up the
VerilogEmitter to more expression inlining.
I considered instead changing
Legalize
to removecvt
(that that's perhaps still a good idea), but I wanted to solve a potential class of future issues and, as far as I can tell, this exact case is the only way to hit this bug currently.Fixes #2035 h/t @drom for finding this issue
Contributor Checklist
Type of Improvement
API Impact
No impact
Backend Code Generation Impact
No impact
Desired Merge Strategy
Release Notes
Fix corner case where
cvt
of a 1-bitSInt
(a no op) could crash the VerilogEmitter if passed as an argument to the shift amount indshl
Reviewer Checklist (only modified by reviewer)
Please Merge
?