p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
680 stars 443 forks source link

type parameter on extern method #871

Closed hanw closed 7 years ago

hanw commented 7 years ago

Following code that uses a generic type parameter on extern method triggers a segmentation fault in the frontend.

#include <core.p4>

struct psa_parser_input_metadata_t {
}

struct psa_parser_output_metadata_t {
    error parser_error;
}

struct psa_ingress_input_metadata_t {
    error parser_error;
}

struct psa_ingress_output_metadata_t {
}

header user_metadata_t {
    bit<8> value;
}

extern lpf<I> {
    lpf(@optional I instance_count);
    T execute<T>(in T data, @optional in I index);
}

parser Parser ( in psa_parser_input_metadata_t mdi, out psa_parser_output_metadata_t mdo);

control Ingress ( in psa_ingress_input_metadata_t md, inout user_metadata_t umd );

control Deparser ( packet_out p, in user_metadata_t umd );

package Switch( Parser p, Ingress ig, Deparser dp );

parser myParser ( in psa_parser_input_metadata_t mdi,
                  out psa_parser_output_metadata_t mdo) {
    state start {
        mdo.parser_error = error.NoError;
        transition accept;
    }
}

control myIngress ( in psa_ingress_input_metadata_t md, inout user_metadata_t umd ) {
    lpf<bit<32>>() lpf_0;
    table color_table {
        key = {
            umd.value : exact;
        }
        actions = {
            NoAction;
        }
    }
    apply {
        umd.value = lpf_0.execute<bit<8>>(0);
        color_table.apply();
    }
}

control myDeparser( packet_out p, in user_metadata_t umd ) {
    apply {
        p.emit(umd);
    }
}

Switch( myParser(), myIngress(), myDeparser() ) main;
mihaibudiu commented 7 years ago

This triggers an infinite recursion in the type-checking pass.

jafingerhut commented 7 years ago

@mbudiu-vmw The latest version of p4c as of 2017-Sep-01 still gives a segmentation fault in my testing when trying to compile the sample program given in the original issue. Is this what you expect?

Sorry, ignore my comment. I see that your fix was committed and is pending merge into p4c as a PR, so my results probably do not surprise you at all.

mihaibudiu commented 7 years ago

I hope that this is fixed, so I will close it.