Skip to content

Conversation

@MathewZach123
Copy link

This PR aims to add a type check for generalized switch statements so that the switch expression is only allowed to be bit<W>, int<W>, enum (with or without an underlying type), or error, matching P4-16 spec https://p4.org/wp-content/uploads/sites/53/2024/10/P4-16-spec-v1.2.5.html#sec-switch-stmt

@MathewZach123 MathewZach123 marked this pull request as draft December 1, 2025 20:03
}
} else {
// switch (expression)
if (!(type->is<IR::Type_Bits>() || type->is<IR::Type_InfInt>() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

What's about typedefs and type aliases? Are they already resolved here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we have any test cases that cover that. Also of potential concern is a Type_Variable (where the type may not have been inferenced yet). Best would be to add test cases to cover all of those.

@MathewZach123 MathewZach123 force-pushed the test_5 branch 3 times, most recently from 3e478ed to 5abda23 Compare December 1, 2025 22:35
@kfcripps kfcripps requested review from ChrisDodd and fruffy December 1, 2025 22:36
@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Dec 1, 2025
@MathewZach123 MathewZach123 marked this pull request as ready for review December 2, 2025 00:07
Signed-off-by: Mathew Suresh Zachariah <[email protected]>
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.

Crash when switch expression is a constant-valued directionless argument Compiler Bug in simplifySwitch.cpp

4 participants