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

Compiler Bug: no definitions #2393

Closed
fruffy opened this issue May 23, 2020 · 1 comment · Fixed by #2743
Closed

Compiler Bug: no definitions #2393

fruffy opened this issue May 23, 2020 · 1 comment · Fixed by #2743
Assignees
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.

Comments

@fruffy
Copy link
Collaborator

fruffy commented May 23, 2020

The following program causes a crash with version:

fruffy@fruffy /m/w/P/p4_tv (master) [1]> p4c/build/p4c --version                             
p4c/build/p4c 
Version 1.2.0 (SHA: bdf588b61 BUILD: RELEASE)
action do_global_action(in bool make_zero, out bool val_undefined) {
    bit<16> tmp;
    tmp = tmp *  (make_zero ? 16w0: 16w1);
}
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
    bool filler_bool = true;
    bool tmp_bool = false;
    action do_action() {
        do_global_action(tmp_bool, tmp_bool);
    }

    table simple_table {
        key = {
            h.eth_hdr.src_addr : exact;
        }
        actions = {
            do_action();
            do_global_action(true, filler_bool);
        }
    }
    apply {
        simple_table.apply();
    }
}

Output:

FrontEnd_31_SimplifyControlFlow
FrontEnd_32_MoveDeclarations
P4::TypeChecking_0_ResolveReferences
P4::TypeChecking_1_TypeInference
SimplifyDefUse_0_TypeChecking
bugs/crash/bools_and_globals.p4(19): [--Wwarn=uninitialized_use] warning: tmp may be uninitialized
    tmp = tmp * (make_zero ? 16w0: 16w1);
          ^^^
bugs/crash/bools_and_globals.p4(17): [--Wwarn=uninitialized_out_param] warning: out parameter val_undefined may be uninitialized when do_global_action terminates
action do_global_action(in bool make_zero, out bool val_undefined) {
                                                    ^^^^^^^^^^^^^
bugs/crash/bools_and_globals.p4(17)
action do_global_action(in bool make_zero, out bool val_undefined) {
       ^^^^^^^^^^^^^^^^
In file: p4_tv/p4c/frontends/p4/def_use.h:351
�[31mCompiler Bug�[0m: no definitions found for tmp

running cc -E -C -undef -nostdinc -x assembler-with-cpp -I p4_tv/p4c/build/p4include -o ./bools_and_globals.p4i bugs/crash/bools_and_globals.p4
running p4_tv/p4c/build/p4c-bm2-ss -I p4_tv/p4c/build/p4include --p4v=16 -vvv -o ./bools_and_globals.json ./bools_and_globals.p4i --arch v1model

bools_and_globals.p4.txt

@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label May 26, 2020
@mihaibudiu mihaibudiu self-assigned this May 26, 2020
@hesingh
Copy link
Contributor

hesingh commented May 27, 2020

The def_use pass should add smarts to detect that a null definition is caused because the variable is inside an action. Or the pass should just elide all the code inside the action because the local computation is useless when the action exits.

@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Apr 21, 2021
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. fixed This topic is considered to be fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants