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

simplifyDefUse: Report the specific uninitialized struct field #4892

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

ChrisDodd
Copy link
Contributor

Rather than reporting the whole struct, report the specific field(s) that is(are) uninitialized.

auto fieldLoc = read->getField(field->name);
auto fieldPoints = currentDefinitions->getPoints(fieldLoc);
if (fieldPoints->containsBeforeStart()) {
warn(ErrorType::WARN_UNINITIALIZED_USE,
Copy link
Contributor

@nv-aefimov nv-aefimov Aug 30, 2024

Choose a reason for hiding this comment

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

I just realized that the default error reporter will only print 1 warning per use since the node is the same for each loop iteration. Is that OK? The user having to recompile each time they add a definition for a field isn't the best experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That can't be true, as some of the changes in expected stderr traces have mulitple fields noted as being uninitialized.

One concern is that a single large struct with many uninitialized fields could trigger a big spew of warnings -- I considered the idea of first finding the uninitialized fields and then emitting a single message based on that (if just a few fields, could list the fields. Could also detect the corner case when no field is initialized)

@ChrisDodd ChrisDodd force-pushed the cdodd-uninit-struct-fields branch from c4e3fa7 to 88415de Compare August 30, 2024 00:26
Rather than reporting the whole struct, report the
specific field(s) that is(are) uninitialized.

Signed-off-by: Chris Dodd <[email protected]>
@ChrisDodd ChrisDodd added this pull request to the merge queue Aug 30, 2024
Merged via the queue into p4lang:main with commit 8ba8c3c Aug 30, 2024
18 checks passed
@ChrisDodd ChrisDodd deleted the cdodd-uninit-struct-fields branch August 30, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants