-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not print confusing warning when a parser state contains an assignment to an l-value slice #4948
Do not print confusing warning when a parser state contains an assignment to an l-value slice #4948
Conversation
c0fa2d6
to
364b582
Compare
parser-unroll-uninitialized-slice-read.p4(5): [--Wwarn=ignore-prop] warning: Result of 'g = f[3:0]' is not defined: Error: Uninitialized | ||
g = f[3:0]; | ||
^ |
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.
The fact that this warning is worded this way is not great - I opened #4945 to improve this and similar warnings
It makes sense to print a warning if only parts of the lvalue are written to but I agree, if we are assigning to the whole slice this warning is unnecessary. On that note, which passes require this interpreter? It is rather hard to maintain and produces lots of confusing warnings like this one. |
The warning itself occurs in the parserUnroll pass. I think to get rid of it you need to insert some logic to check that the slice being assigned properly. We can also fix the warning there. |
Can you elaborate why it makes sense to emit an "uninitialized" warning when even a partial slice is written? My motivation for this PR is that no warning should even be emitted in this case. Why should writing to an uninitialized field slice be treated any differently than writing to an uninitialized whole field, which results in no such warning?
My understanding is that it is used by the
Are you referring to the "s.f may be uninitialized" or "Result of 's.f[3:0] = 4w2' is not defined: Error: Uninitialized" warning? The |
Well, this was assuming the warning makes sense at all and there was a particular motivation why it was put there for an assignment statement. In the case of a partial write, there are still some uninitialized bits which could have unpredictable values.
I think there is no one left that understands this pass but it might make sense to change the success criterion here: https://github.com/p4lang/p4c/blob/main/midend/parserUnroll.cpp#L470
The latter, although I also assumed that this pass triggered SimplifyDefUse in some form. If that pass is throwing the warning we should fix probably fix it because it is a much more commonly used pass. |
The point of this PR is that I don't believe this warning makes sense at all. Yes, a read of a potentially uninitialized slice should result in a warning, but a warning for a write to such slice is useless. You can see from the attached tests that the latter now results in no warning, but the former still does result in a warning. Furthermore, I have found no evidence in the code or in the history that this warning was intentionally added. It seems more likely to be an oversight to me (the author of
Is there a particular reason that modifying the success criterion here is preferable to the changes I have made to
To my knowledge |
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.
My main concern is understanding how or what it even means in the interpreter to evaluate an lvalue in postorder here. Is that even supposed to happen? I think your solution is fine but it might be more of a band-aid.
It makes sense to handle this warning on higher-levels, e.g., in the parserUnroll pass, which is throwing an error on resolving an lvalue.
The reason I am concerned about SimplifyDefUse is that it has a different logic but is throwing the same type of error.
return; | ||
// This cannot be an uninitialized read if 'expression' is the LHS of | ||
// an assignment to a sliced l-value. | ||
if (!evaluatingLeftValue) { |
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.
I would throw a BUG if the value is an lval and the ternary is not a slice. To make sure we do not end up in weird states.
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.
Done
In theory, I think an error may still occur when evaluating LHS in other cases. For example, an assignment to an |
5c6884a
to
a24abc9
Compare
…ment to an l-value slice Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
a24abc9
to
ede58b6
Compare
I don't think it makes sense to print a warning about an l-value being uninitialized when either the entire l-value or a slice of said l-value is written to.
On
main
branch, the added P4 program results in:and on this branch:
Ideally both warnings would be gotten rid of, but I don't know how to get rid of the first one, and the second one is the most confusing to me. This is at least an improvement over the previous behavior. I am open to suggestions if anyone has any ideas of how to get rid of the first warning also.