From d24754285221ebd8754e9afba7043efe9cb5755d Mon Sep 17 00:00:00 2001 From: Emre Orbay Date: Fri, 6 Dec 2024 03:18:06 -0800 Subject: [PATCH] Ignore typeless structs in unstructured annotations This pass expects struct expressions in unstructured annotations to have explicit types. Using { } in unstructured annotation is actually allowed by the language spec, it does not make sense for the frontend to prevent this (in fact any sequence of tokens can be used as long as parentheses are balanced). nvp4c will need to use untyped struct expressions in this context to allow the user to provide values for the fields of headers. Signed-off-by: Chris Dodd --- frontends/p4/specializeGenericTypes.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontends/p4/specializeGenericTypes.cpp b/frontends/p4/specializeGenericTypes.cpp index b6c64ab06c..d1ab5a8d36 100644 --- a/frontends/p4/specializeGenericTypes.cpp +++ b/frontends/p4/specializeGenericTypes.cpp @@ -167,6 +167,9 @@ const IR::Node *ReplaceTypeUses::postorder(IR::Type_Specialized *type) { } const IR::Node *ReplaceTypeUses::postorder(IR::StructExpression *expression) { + const IR::Annotation *anNode = findContext(); + if (anNode != nullptr && !anNode->structured) return expression; + auto st = getOriginal()->structType; if (!st) { ::P4::error(ErrorType::ERR_TYPE_ERROR,