p4lang / p4c

P4_16 reference compiler

Home Page:https://p4.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kfcripps opened this issue · comments

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.