p4c
p4c copied to clipboard
Compiler BUG in def_use.h with multiple use of enum const
A stripped down case hits the BUG_CHECK when run through p4test:
enum bit<16> EtherType {
IPV4 = 16w0x800,
IPV6 = 16w0x86dd
}
extern void func(in EtherType et);
const EtherType type1 = EtherType.IPV4;
control c() {
apply {
func(type1);
func(type1);
}
}
package P<C>(C main);
P<_>(c()) main;
gives
% p4test issue.p4
In file: /Users/cdodd/p4org-p4c/frontends/p4/def_use.h:514
Compiler Bug: issue.p4(8): Expression EtherType write set already set
const EtherType type1 = EtherType.IPV4;
^^^^^^^^^
the problem seems to come from having two uses of a const with an enum type.
Commenting out the BUG_CHECK seems to avoid the problem and allows things to complete normally, but there's probably some invariant or assumption in DefUse/ComputWriteSet code that is invalid
Unfortunately, we currently do not have people dedicated to fixing bugs in the front-end.
I plan to look into this, but it is a bit down on my todo list.
So it looks like this problem has gone away -- it no longer reproduces with this example, and doesn't crop up in other more complex cases either. It is possible that the reorg of def_use around loops fixed it, or it may have been obscured. But for now, I'm just going to close this bug.