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

Contribute DiagnosticCountInPassHook #4629

Merged
merged 8 commits into from
Apr 25, 2024
Merged

Contribute DiagnosticCountInPassHook #4629

merged 8 commits into from
Apr 25, 2024

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Apr 18, 2024

This is the reason behind #4626. A pass manager hook that is useful for testing (p4test-like) the compiler output or just for the developers to see what passes emit diagnostic messages.

Example output (with the hook in driver added and running with -TdiagnosticCountInPass:1):

main.p4(65): [--Wwarn=parser-transition] warning: sub_parser: implicit transition to `reject'
           state sub_parser{
                 ^^^^^^^^^^
PASS FrontEnd ~> CreateBuiltins emitted 1 warning
[--Wwarn=parser-transition] warning: SelectCase: unreachable case
PASS MidEnd ~> PassRepeated emitted 1 warning

@vlstill vlstill self-assigned this Apr 18, 2024
@vlstill vlstill marked this pull request as ready for review April 18, 2024 18:49
@vlstill vlstill added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Apr 18, 2024
@vlstill vlstill requested a review from fruffy April 18, 2024 18:49
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Could be nice to have an example exercising this hook.

ir/pass_utils.cpp Outdated Show resolved Hide resolved
ir/pass_utils.h Show resolved Hide resolved
ir/pass_utils.cpp Outdated Show resolved Hide resolved
Co-authored-by: Fabian Ruffy <[email protected]>
@vlstill
Copy link
Contributor Author

vlstill commented Apr 23, 2024

Could be nice to have an example exercising this hook.

Let me at it to P4test, the output has to be enabled anyway so it should not break anything.

has to be activated by -TdiagnosticCountInPass:1 to run
@vlstill
Copy link
Contributor Author

vlstill commented Apr 23, 2024

$ ./p4c/p4test -TdiagnosticCountInPass:1 <(printf 'const bit<42> x = -4;\nconst bit<16> y = (bit<16>)x;\nvoid foo() { return 4; }')
/dev/fd/63(1): [--Wwarn=mismatch] warning: -42w4: negative value with unsigned type
const bit<42> x = -4;
                   ^
/dev/fd/63(1): [--Wwarn=mismatch] warning: 16w4398046511100: value does not fit in 16 bits
const bit<42> x = -4;
                   ^
PASS ConstantFolding ~> DoConstantFolding emitted 2 warnings
/dev/fd/63(3): [--Werror=type-error] error: return 4: return expression in function with void return
void foo() { return 4; }
             ^^^^^^
PASS FrontEnd ~> P4::TypeInference emitted 1 error

@vlstill
Copy link
Contributor Author

vlstill commented Apr 23, 2024

I've further extended this to provide better info in cases like parser errors:

$ ./p4c/p4test -TdiagnosticCountInPass:1 <(printf 'const bit<42> x = -4;\nconst bit<16> y = (bit<16>)x\nvoid foo() { return 4; }')                                     /dev/fd/63(3):syntax error, unexpected VOID, expecting ;
void
^^^^
[--Werror=overlimit] error: 1 errors encountered, aborting compilation
PARSER emitted 2 errors

@vlstill vlstill enabled auto-merge April 23, 2024 14:59
@vlstill vlstill disabled auto-merge April 23, 2024 14:59
@vlstill vlstill enabled auto-merge April 25, 2024 06:52
@vlstill
Copy link
Contributor Author

vlstill commented Apr 25, 2024

Any idea what is wrong with the Fedora build?

/__w/p4c/p4c/build/_deps/abseil-src/absl/numeric/internal/bits.h:309:24: error: '__builtin_ctzs' needs isa option -mbmi

@fruffy
Copy link
Collaborator

fruffy commented Apr 25, 2024

Any idea what is wrong with the Fedora build?

/__w/p4c/p4c/build/_deps/abseil-src/absl/numeric/internal/bits.h:309:24: error: '__builtin_ctzs' needs isa option -mbmi

It looks like Fedora GCC switched from 13 to 14 and this instruction now needs an option.

@vlstill vlstill added this pull request to the merge queue Apr 25, 2024
Merged via the queue into main with commit ef2c8ae Apr 25, 2024
16 of 17 checks passed
@vlstill vlstill deleted the vstill/diag-count-hook branch April 25, 2024 23:52
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.

2 participants