p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Compiler BUG in def_use.h with multiple use of enum const

Open ChrisDodd opened this issue 1 year ago • 2 comments

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

ChrisDodd avatar Feb 15 '24 23:02 ChrisDodd

Unfortunately, we currently do not have people dedicated to fixing bugs in the front-end.

fruffy avatar Feb 16 '24 14:02 fruffy

I plan to look into this, but it is a bit down on my todo list.

ChrisDodd avatar Feb 19 '24 21:02 ChrisDodd

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.

ChrisDodd avatar May 23 '24 01:05 ChrisDodd