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

Allow --Wdisable to take precedence over --Werror for warning messages #4894

Merged
merged 8 commits into from
Sep 17, 2024

Conversation

kfcripps
Copy link
Contributor

@kfcripps kfcripps commented Sep 3, 2024

This reverts a change that was introduced by #4366, and is in fact redundant for the purpose of #4366 (it was originally necessary, but later became redundant after updates were made to that PR). Not only was it redundant, but it also introduced some undesired behavior (see #4365 (comment) and related discussion). Edit: See #4894 (comment)

For the following P4 program:

header h_t {
    bit<28> f1;
    bit<4> f2;
}

extern void __e(in bit<28> arg);

control C() {
    action foo() {
        h_t h;
        __e(h.f1);
    }

    table t {
        actions = { foo; }
        default_action = foo;
    }

    apply {
        t.apply();
    }
}

control proto();
package top(proto p);

top(C()) main;

The command-line options p4test tmp.p4 --dump tmp --Werror --Wdisable=uninitialized_use --Wdisable=invalid_header currently result in:

tmp.p4(28): [--Werror=invalid_header] error: accessing a field of an invalid header h
        __e(h.f1);
            ^
tmp.p4(28): [--Werror=uninitialized_use] error: h.f1 may be uninitialized
        __e(h.f1);
            ^^^^

but should result in no errors or warnings.

Signed-off-by: Kyle Cripps <kyle@pensando.io>
@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Sep 3, 2024
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Copy link

@ajwalton ajwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a test-case for this?

(From what I can see, the code is OK.)

@kfcripps
Copy link
Contributor Author

kfcripps commented Sep 5, 2024

Should there be a test-case for this?

(From what I can see, the code is OK.)

I do not know how to test command-line options using the existing infrastructure.

@ajwalton
Copy link

ajwalton commented Sep 5, 2024

Should there be a test-case for this?
(From what I can see, the code is OK.)

I do not know how to test command-line options using the existing infrastructure.

Me neither, I'm afraid. @vlstill, @fruffy, @ChrisDodd ?

…emoted

Signed-off-by: Kyle Cripps <kyle@pensando.io>
@kfcripps
Copy link
Contributor Author

kfcripps commented Sep 5, 2024

Apologies, I forgot about diagnostics that are both errors and warnings. The original changes I proposed in this PR will not work. @ajwalton Please see the new changes.

Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
@fruffy
Copy link
Collaborator

fruffy commented Sep 5, 2024

Should there be a test-case for this?
(From what I can see, the code is OK.)

I do not know how to test command-line options using the existing infrastructure.

Me neither, I'm afraid. @vlstill, @fruffy, @ChrisDodd ?

You can set up tests in CMake with custom arguments like this: https://github.com/p4lang/p4c/blob/main/backends/p4test/CMakeLists.txt#L118

I do not recall whether this also supports reference files, however.

Signed-off-by: Kyle Cripps <kyle@pensando.io>
@kfcripps
Copy link
Contributor Author

kfcripps commented Sep 5, 2024

@ajwalton @fruffy Ok but it seems like the precedent before this PR was to not add such tests when changing the behavior of options such as e.g. --Werror / --Wdisable, so adding such tests would set a new precedent, which I believe is out of scope of this PR.

Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
@kfcripps
Copy link
Contributor Author

kfcripps commented Sep 5, 2024

Sorry for all of the updates. The PR is now ready for review (and I will squash all commits when merging).

@kfcripps kfcripps requested review from asl, jafingerhut, vlstill, ajwalton and fruffy and removed request for asl, jafingerhut, vlstill, fruffy and ajwalton September 10, 2024 23:17
Copy link
Contributor

@asl asl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fruffy
Copy link
Collaborator

fruffy commented Sep 11, 2024

@ajwalton @fruffy Ok but it seems like the precedent before this PR was to not add such tests when changing the behavior of options such as e.g. --Werror / --Wdisable, so adding such tests would set a new precedent, which I believe is out of scope of this PR.

I think the precedent exists primarily because of neglect, not because of a conscious decision. We should consider building some test infrastructure that makes parameter/feature flag tests like these easier to add.

@kfcripps
Copy link
Contributor Author

kfcripps commented Sep 11, 2024

@ajwalton @fruffy Ok but it seems like the precedent before this PR was to not add such tests when changing the behavior of options such as e.g. --Werror / --Wdisable, so adding such tests would set a new precedent, which I believe is out of scope of this PR.

I think the precedent exists primarily because of neglect, not because of a conscious decision. We should consider building some test infrastructure that makes parameter/feature flag tests like these easier to add.

@fruffy I agree that we should build such testing mechanism. I am just saying that it can and should be done independently in a different PR.

For now I will be happy to manually generate and share the output of any combination of options.

@kfcripps
Copy link
Contributor Author

@fruffy I agree that we should build such testing mechanism. I am just saying that it can and should be done independently in a different PR.

I opened #4907 for this purpose.

@fruffy
Copy link
Collaborator

fruffy commented Sep 11, 2024

@ajwalton @fruffy Ok but it seems like the precedent before this PR was to not add such tests when changing the behavior of options such as e.g. --Werror / --Wdisable, so adding such tests would set a new precedent, which I believe is out of scope of this PR.

I think the precedent exists primarily because of neglect, not because of a conscious decision. We should consider building some test infrastructure that makes parameter/feature flag tests like these easier to add.

@fruffy I agree that we should build such testing mechanism. I am just saying that it can and should be done independently in a different PR.

For now I will be happy to manually generate and share the output of any combination of options.

No problem, not requesting it for this particular PR but something we should definitely keep track of if it keeps coming up.

@kfcripps
Copy link
Contributor Author

Does anyone else want to review this? If not, I'll probably merge this soon.

@kfcripps kfcripps added this pull request to the merge queue Sep 17, 2024
Merged via the queue into p4lang:main with commit 598119b Sep 17, 2024
18 checks passed
@kfcripps kfcripps deleted the 4365-1 branch September 17, 2024 20:28
linuxrocks123 pushed a commit to linuxrocks123/p4c that referenced this pull request Sep 18, 2024
…sages (p4lang#4894)

* Allow --Wdisable to take precedence over --Werror for warning messages

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

* Add const qualifier

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

* Make sure to still prevent errors that are also warnings from being demoted

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

* appease cpplint

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

* appease cpplint

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

* Replace all ::warning(ErrorType::ERR_* with ErrorType::WARN_*

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

* ERR_DUPLICATE -> WARN_DUPLICATE

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

* invert logic

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

---------

Signed-off-by: Kyle Cripps <kyle@pensando.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants