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

Constant folding of bit width expressions is no longer complete #4656

Closed
kfcripps opened this issue May 8, 2024 · 0 comments · Fixed by #4657
Closed

Constant folding of bit width expressions is no longer complete #4656

kfcripps opened this issue May 8, 2024 · 0 comments · Fixed by #4657
Labels
bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser) regression Code that previously compiled correctly either no longer compiles or produces invalid results.

Comments

@kfcripps
Copy link
Contributor

kfcripps commented May 8, 2024

With 01fedcc, compiling the following P4 program:

header h_t {
    bit<((10 == 1 ? 1 : 10 + 1) * (8+1))> f;
}

control C() {
    action bar() {
    }

    table t {
        actions = { bar; }
        default_action = bar;
    }

    apply {
        t.apply();
    }
}

control proto();
package top(proto p);

top(C()) main;

expectedly yields:

header h_t {
    bit<99> f;
}

control C() {
    @name("C.bar") action bar() {
    }
    @name("C.t") table t_0 {
        actions = {
            bar();
        }
        default_action = bar();
    }
    apply {
        t_0.apply();
    }
}

control proto();
package top(proto p);
top(C()) main;

but 4a74084 causes it to result in an error instead:

t.p4(2): [--Werror=expected] error: *: expected a constant
    bit<((10 == 1 ? 1 : 10 + 1) * (8+1))> f;
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label May 8, 2024
@kfcripps kfcripps added the regression Code that previously compiled correctly either no longer compiles or produces invalid results. label May 9, 2024
@kfcripps kfcripps added the bug This behavior is unintended and should be fixed. label May 10, 2024
github-merge-queue bot pushed a commit that referenced this issue May 15, 2024
…itchCase` `label` expressions, instead of delaying constant folding of all `IR::Mux` expressions (#4657)

* Delay constant folding IR::Mux expressions only if we are inside of a label of an action enum SwitchStatement

* Apply IR::Mux constant folding logic to all switch case labels. We don't know if it is an action enum switch statement until after type inference has run.

* Move issue3699 test to p4_16_samples/ as we now have the proper fix for #3699

* Add IR::SwitchCase preorder function instead of visiting all IR::Mux expressions.

* appease cpplint

* try to appease cpplint

* Add test with compile-time constant expressions in labels of regular switch statement labels

* Explicitly check whether SwitchCase belongs to a SwitchStatement with action_run expression

* appease p4c-lint

* Invert logic to skip visiting action_run SwitchCase labels

* Move isActionRun() to anonymous namespace

* Add comment about static_cast
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. core Topics concerning the core segments of the compiler (frontend, midend, parser) regression Code that previously compiled correctly either no longer compiles or produces invalid results.
Projects
None yet
1 participant