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

Compiler Bug: At this point in the compilation typechecking should not infer new types anymore, but it did. #2190

Closed
fruffy opened this issue Feb 5, 2020 · 8 comments
Assignees
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.

Comments

@fruffy
Copy link
Collaborator

fruffy commented Feb 5, 2020

Hello again,
after commit 1159ced we encounter the compiler bug in the title for specific programs. I attached an example.
The exact command is p4c/build/p4c -v bad_type_checking.p4.
bad_type_checking.p4.txt

@mihaibudiu mihaibudiu self-assigned this Feb 5, 2020
@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Feb 5, 2020
@mihaibudiu
Copy link
Contributor

We should only add the numbers if they have the same type.

mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue Feb 7, 2020
@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Feb 7, 2020
@jafingerhut
Copy link
Contributor

jafingerhut commented Feb 7, 2020

A question about this strength reduction transformation that sometimes changes ((a >> b) >> c) to (a>> (b + c)). Could the transformation be done if the type of the expression (b+c) is bit<W>, and the addition of (b+c) wraps around? It seems that the original ((a >> b) >> c) might have a correct result of 0, whereas if (b+c) wrapped around to 1, (a >> (b+c)) could be a non-0 (a >> 1) value.

@mihaibudiu
Copy link
Contributor

Yes, with the current code this can happen.
We could also only do it if both b and c are InfInt.

@mihaibudiu
Copy link
Contributor

Please file another issue.

@mihaibudiu
Copy link
Contributor

Or perhaps let's fix it in this PR, just request changes.

@mihaibudiu
Copy link
Contributor

@fruffy can you catch this overflow bug?

@fruffy
Copy link
Collaborator Author

fruffy commented Feb 7, 2020

Yes, I tested it on the branch. I attached a sample program and stf file.
The overflow causes the shift to turn to zero.
addition_overflow.p4.txt
addition_overflow.stf.txt

@fruffy
Copy link
Collaborator Author

fruffy commented Feb 7, 2020

Output of the tool once it detected a difference is something like this:

FrontEnd_13_BindTypeVariables:
mk_Parsed_packet(
	mk_ethernet_t(
		dstAddr(eth(hdr(ingress_0))),
		srcAddr(eth(hdr(ingress_0))),
		etherType(eth(hdr(ingress_0)))),
	 mk_H(
		 0, <--- value of hdr.h.a
		 b(h(hdr(ingress_0))))
	)
)

FrontEnd_17_StrengthReduction:
mk_Parsed_packet(
	mk_ethernet_t(
		dstAddr(eth(hdr(ingress_0))),
		srcAddr(eth(hdr(ingress_0))),
		etherType(eth(hdr(ingress_0)))),
	 mk_H(
		 1, <--- value of hdr.h.a
		 b(h(hdr(ingress_0))))
	)
)

So the value of hdr.h.a after running through the control pipeline is 1 instead of 0.

mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.
Projects
None yet
Development

No branches or pull requests

3 participants