Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kfcripps
Copy link
Contributor

@kfcripps kfcripps commented Oct 7, 2024

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:

$ p4test tmp.p4 --dump t --loopsUnroll
tmp.p4(9): [--Wwarn=uninitialized_use] warning: s.f may be uninitialized
        s.f[3:0] = 2;
        ^^^
tmp.p4(9): [--Wwarn=ignore-prop] warning: Result of 's.f[3:0] = 4w2' is not defined: Error: Uninitialized
        s.f[3:0] = 2;
                 ^

and on this branch:

$ p4test tmp.p4 --dump t --loopsUnroll
tmp.p4(9): [--Wwarn=uninitialized_use] warning: s.f may be uninitialized
        s.f[3:0] = 2;
        ^^^

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.

@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Oct 7, 2024
Signed-off-by: Kyle Cripps <[email protected]>
@kfcripps kfcripps force-pushed the fix-parser-slice-assignment-warning branch from 58cb619 to c0fa2d6 Compare October 7, 2024 17:07
Signed-off-by: Kyle Cripps <[email protected]>
@kfcripps kfcripps force-pushed the fix-parser-slice-assignment-warning branch from c0fa2d6 to 364b582 Compare October 7, 2024 17:10
Comment on lines +10 to +12
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];
^
Copy link
Contributor Author

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

@fruffy
Copy link
Collaborator

fruffy commented Oct 8, 2024

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.

@fruffy
Copy link
Collaborator

fruffy commented Oct 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants