From 18bfccb2a2c720bb5bd242e2605b5a7a7fded64d Mon Sep 17 00:00:00 2001 From: fruffy Date: Tue, 3 Dec 2024 20:25:23 -0500 Subject: [PATCH] Fix incorrect annotation parsing in Tofino. Signed-off-by: fruffy --- backends/tofino/bf-p4c/bf-p4c-options.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backends/tofino/bf-p4c/bf-p4c-options.cpp b/backends/tofino/bf-p4c/bf-p4c-options.cpp index 5ad102b7eb..c7d5efd201 100644 --- a/backends/tofino/bf-p4c/bf-p4c-options.cpp +++ b/backends/tofino/bf-p4c/bf-p4c-options.cpp @@ -905,24 +905,24 @@ BFNOptionPragmaParser::parseCompilerOption(const IR::Annotation *annotation) { // Parsing of option pragmas is done early in the compiler, before P4₁₆ // annotations are parsed, so we are responsible for doing our own parsing // here. - auto args = &annotation->getExpr(); - if (args->empty()) { - auto parseResult = + const IR::Vector *args = nullptr; + if (annotation->needsParsing()) { + args = P4::P4ParserDriver::parseExpressionList(annotation->srcInfo, annotation->getUnparsed()); - if (parseResult != nullptr) { - args = parseResult; - } + } else { + args = &annotation->getExpr(); } + CHECK_NULL(args); bool first = true; - for (auto *arg : *args) { + for (const auto *arg : *args) { // Try to convert the parsed expression to a valid option string cstring optionString = ""_cs; - if (auto *argString = arg->to()) { + if (const auto *argString = arg->to()) { optionString = argString->value; } else { // The expression is not a IR::StringLiteral, but it can still be a valid integer - if (auto *argConstant = arg->to()) { + if (const auto *argConstant = arg->to()) { optionString = std::to_string(argConstant->asInt()); } else { // The expression is neither a IR::StringLiteral or IR::Constant and so is invalid @@ -932,7 +932,7 @@ BFNOptionPragmaParser::parseCompilerOption(const IR::Annotation *annotation) { } } - if (first && !cmdLinePragmas.count(optionString)) { + if (first && (cmdLinePragmas.count(optionString) == 0U)) { ::warning("Unknown @pragma command_line %1%", annotation); return std::nullopt; }