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

Result of extern function call used in switch expression is incorrectly marked as a compile-time constant #4661

Closed
kfcripps opened this issue May 10, 2024 · 0 comments · Fixed by #4726
Labels
bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser)

Comments

@kfcripps
Copy link
Contributor

kfcripps commented May 10, 2024

Compiling

#include <core.p4>

extern void foo();
extern void bar();
extern bit<8> baz();
action a(){}
action b(){}
control c() {
    table t  {
        actions = { a ; b;  }
    }
    apply {
        switch(baz()) {
            1 : { foo(); }
            4 : { bar(); }
        }
        t.apply();
    }
}

control C();
package top(C c);

top(c()) main;

results in the following warning:

t.p4(13): [--Wwarn=mismatch] warning: baz(): constant expression in switch
        switch(baz()) {
               ^^^^^

I'm not sure if the warning is the only observable problem. Classifying the result of the extern function call as a compile-time constant could have a less benign effect somewhere else.

@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label May 10, 2024
@fruffy fruffy 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 Jul 11, 2024
…me constants. (#4726)

* Do not mark argument-less extern method calls as compile-time constants.

Signed-off-by: kfcripps <kyle@pensando.io>

* Only mark pure extern function calls with const args as compile-time constants

Signed-off-by: kfcripps <kyle@pensando.io>

* Add tests

Signed-off-by: kfcripps <kyle@pensando.io>

* Fixes for static_assert() and factory extern functions

Signed-off-by: kfcripps <kyle@pensando.io>

* Appease cpplint

Signed-off-by: kfcripps <kyle@pensando.io>

* Do not unconditionally mark results of pure extern method function calls as compile-time constants

Signed-off-by: kfcripps <kyle@pensando.io>

* Also check for IR::Type_SpecializedCanonical with base type of IR::Type_Extern

Signed-off-by: kfcripps <kyle@pensando.io>

---------

Signed-off-by: kfcripps <kyle@pensando.io>
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)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants