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

Type checker fails to reject compile-time out-of-bounds access to a header stack #5095

Open
jaehyun1ee opened this issue Jan 12, 2025 · 0 comments
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Comments

@jaehyun1ee
Copy link

As mentioned in Section 8.18, any reference to an element of a header stack hs[index] where index is a compile-time known value must give an error at compile time if the value of the index is out of range.

The spec disallows an out-of-bounds access to a header stack, if the index is a compile-time known value.

However, p4c fails to reject minsize.p4.

typedef bit<32> T;

header H {}

control c(out bit<32> v) {
    apply
    {
        bit<32> b;
        H[0] h;

        v = b.minSizeInBits() + T.minSizeInBits() + b.maxSizeInBits() + T.maxSizeInBits() + h[0].minSizeInBits();
        // h[0] is an out-of-bounds access
    }
}

const int w = T.maxSizeInBits();

control cproto(out bit<32> v);
package top(cproto _c);

top(c()) main;
@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

No branches or pull requests

2 participants