Skip to content

Conversation

@jhavrane
Copy link
Contributor

@jhavrane jhavrane commented Dec 9, 2025

Adds missing validation for v1model value constant. Fixes #5296

Signed-off-by: Jiri Havranek <jiri.havranek@altera.com>
@jhavrane jhavrane self-assigned this Dec 9, 2025
@jhavrane
Copy link
Contributor Author

jhavrane commented Dec 9, 2025

Also tried with value from the issue:

Error compiling
issue5296.p4(2): [--Werror=expected] error: error.pkt: expected v1model version to be a non-negative number
const bit<32> __v1model_version = error.pkt;
                                  ^^^^^^^^^

bool preorder(const IR::Declaration_Constant *dc) override {
if (dc->name == "__v1model_version") {
const auto *val = dc->initializer->to<IR::Constant>();
if (!val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should be if (!val || val->value < 0). The only reason this seems to work without it is because -6419018 is initially IR::Neg on an IR::Constant, and if constant-folding runs it will be simplified.

Might also want to limit it to just known valid versions of V1MODEL_VERSION

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ChrisDodd, is there any list of valid versions of V1MODEL_VERSION somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grepped this list of versions from testdata/

20160101
20180000
20180101
20200000
20200408

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Dec 10, 2025
jhavrane and others added 25 commits December 12, 2025 09:27
Signed-off-by: Jiri Havranek <jiri.havranek@altera.com>
Signed-off-by: Jiri Havranek <jiri.havranek@altera.com>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Michal Kekely <michal.kekely@altera.com>
Signed-off-by: Michal Kekely <michal.kekely@altera.com>
Signed-off-by: Mouse <mouse@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Co-authored-by: Mouse <mouse@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Bryan Richter <b@chreekat.net>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…n the `ErrorCatalog` (p4lang#5360)

Signed-off-by: kfcripps <kyle@pensando.io>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Vineet1101 <Vineetgoel692@gmail.com>
Signed-off-by: KunJeong <kunjeong99@naver.com>
Signed-off-by: Bryan Richter <b@chreekat.net>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
dependabot bot and others added 30 commits December 19, 2025 11:33
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Bryan Richter <b@chreekat.net>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Bryan Richter <b@chreekat.net>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Co-authored-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Co-authored-by: Jamal Hadi Salim <jhs@mojatatu.com>
Co-authored-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Co-authored-by: rst0git <9142901+rst0git@users.noreply.github.com>
Signed-off-by: fruffy <fruffy@nyu.edu>
…king again (p4lang#5424)

Signed-off-by: Andy Fingerhut <andy_fingerhut@alum.wustl.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Co-authored-by: fruffy <fruffy@nyu.edu>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
…actually valid (p4lang#5417)

Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Co-authored-by: Jamal Hadi Salim <jhs@mojatatu.com>
Co-authored-by: Pedro Tammela <pctammela@mojatatu.com>
Co-authored-by: rst0git <9142901+rst0git@users.noreply.github.com>
Signed-off-by: Vladimir Still <dev.p4@vstill.eu>
Signed-off-by: Denis Matousek <denis.matousek@altera.com>
Co-authored-by: Denis Matousek <denis.matousek@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Denis Matousek <denis.matousek@altera.com>
Co-authored-by: Denis Matousek <denis.matousek@altera.com>
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Denis Matousek <denis.matousek@altera.com>
Co-authored-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Jiri Havranek <jiri.havranek@altera.com>
Signed-off-by: Jiri Havranek <jiri.havranek@altera.com>
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.

SIGSEGV when wrong initializer is given to __v1model_version