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

Correct issue where getSourceLine() could return -1 mod 2^32 instead … #577

Closed
wants to merge 2 commits into from
Closed

Correct issue where getSourceLine() could return -1 mod 2^32 instead … #577

wants to merge 2 commits into from

Conversation

jafingerhut
Copy link
Contributor

…of 0

@jafingerhut
Copy link
Contributor Author

jafingerhut commented May 7, 2017

There are other cases I have noticed where the SourceInfo objects created by the compiler for synthesized code is a bit odd, but I will save enhancing those issues for later.

This can cause bmv2 to crash. I have a separate PR open to correct the issue on that side: p4lang/behavioral-model#356

but p4c-bm2-ss really shouldn't generate 2^32-1 as a line number.

// except in the special case of all 0s, where 0 is preferable to
// (-1 mod 2^32)
if (line == 0 && it->first == 0 && it->second.sourceLine == 0) {
return SourceFileLine(it->second.fileName, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that this should never happen, and if it does, it indicates a bug somewhere else. So it might be better to have a BUG_CHECK here rather than silently covering up the problem.

Copy link
Contributor Author

@jafingerhut jafingerhut May 9, 2017

Choose a reason for hiding this comment

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

If you compile this program: https://github.com/jafingerhut/p4-guide/blob/master/demo5/demo5.p4_16.p4#L89

using the command p4c-bm2-ss -o tmp.json demo5.p4_16.p4, the action top_level_action, being defined at the top level, and having an inout struct of all headers, but only modifying one field of one header inside of that struct, is compiled to contain several copy_header calls synthesized by the compiler to implement the copy-in and copy-out semantics. One of those has source info of 2^32-1 in the JSON output, which becomes 0 if you make the diff suggested in this PR.

This might very well be a bug elsewhere in the compiler, but I haven't tried to trace it backwards from the point of this change.

While I have your thoughts on this issue, these lists of copy-in and copy-out copy_header primitives can get very very long if the 'headers' struct contains many headers, and in other similar cases. Are they strictly necessary? If so, why?

If they are there just because it was the quickest and easiest way to guarantee that copy-in copy-out semantics are followed, and a fancier compiler could reduce the list by doing an analysis of fields actually read or written inside the action, then I understand the desire to keep things simple.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added a fix (PR #588) that fixes the problem with the json generation code that was triggering the problem you see (and which isn't really fixed by this -- it will just output 0 as the line number to avoid crashing BMV2, rather than the correct line number)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Closing this PR in favor of @ChrisDodd better one: #588

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