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

Calling an extern with a local variable: read-only error #2545

Closed
fruffy opened this issue Sep 14, 2020 · 1 comment · Fixed by #2559
Closed

Calling an extern with a local variable: read-only error #2545

fruffy opened this issue Sep 14, 2020 · 1 comment · Fixed by #2559
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 Sep 14, 2020

Not sure about this one:
The following program

extern bit<64> call_extern(inout Headers val);
control ingress(inout Headers h) {
    apply {
        Headers tmp = h;
        call_extern(tmp);
        h = tmp;
    }

calls an extern on a local variable.
The error I get is

MidEnd_12_StrengthReduction
MidEnd_13_EliminateTuples
MidEnd_14_SimplifyComparisons
MidEnd_15_CopyStructures
MidEnd_16_NestedStructs
bugs/crash/struct_call_extern.p4(12): [--Werror=type-error] error: : Read-only value used for out/inout parameter val
extern bit<64> call_extern(inout Headers val);
                                         ^^^
Done.

Is this intentional?
call_extern_with_struct.p4.txt

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

This is an interesting case. p4test contains a pass which indeed does not support extern functions with out arguments that are nested structs. This pass is usable as a mid-end pass for p4c-bm2-ss, but it is not a general-purpose pass. I will improve the compiler to give an error for this case rather than generating an illegal program. This is a case where p4test is too restrictive; it does not handle arbitrary legal p4 programs.

@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Sep 21, 2020
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.

2 participants