Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions backends/p4tools/modules/smith/common/declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,20 @@ IR::Declaration_Variable *DeclarationGenerator::genVariableDeclaration() {
auto *expr = target().expressionGenerator().genExpression(tp);
ret = new IR::Declaration_Variable(name, tp, expr);
} else if (tp->is<IR::Type_Array>()) {
// header stacks do !have an initializer yet
ret = new IR::Declaration_Variable(name, tp);
IR::Vector<IR::Expression> elems;
const IR::Type_Array *arrayTp = dynamic_cast<const IR::Type_Array *>(tp);
for (unsigned i = 0; i < arrayTp->getSize(); i++) {
const IR::Expression *elem =
target().expressionGenerator().genExpression(arrayTp->elementType);
// To be safe, cast tuple expressions to the element type
if (elem->is<IR::ListExpression>()) {
elems.push_back(new IR::Cast(arrayTp->elementType, elem));
} else {
elems.push_back(elem);
}
}
IR::ListExpression *init = new IR::ListExpression(elems);
ret = new IR::Declaration_Variable(name, tp, init);
} else {
BUG("Type %s not supported!", tp->node_type_name());
}
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/modules/smith/scripts/compilation-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ KNOWN_BUGS=(
"Cannot evaluate initializer for constant"
"Null expr"
"error: retval_1: declaration not found" # V1model failure.
"Compiler Bug: Cannot find declaration for inlinedRetval" # See #5549
"At this point in the compilation typechecking should not infer new types anymore" # See #5560
)

# Function to check if an error is triggered by a known bug.
Expand Down
Loading