Skip to content

Commit

Permalink
Do not specialize functions when arguments are type variables (#3328)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
  • Loading branch information
Mihai Budiu authored May 17, 2022
1 parent ee419ee commit ecb2c7b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontends/p4/specializeGenericFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace P4 {
bool FindFunctionSpecializations::preorder(const IR::MethodCallExpression* mce) {
if (!mce->typeArguments->size())
return false;
// We only specialize if the type arguments are not type variables
for (auto arg : *mce->typeArguments) {
auto type = specMap->typeMap->getTypeType(arg, true);
if (type->is<IR::ITypeVar>())
return false;
}
MethodInstance *mi = MethodInstance::resolve(mce, specMap->refMap, specMap->typeMap);
if (auto func = mi->to<FunctionCall>()) {
LOG3("Will specialize " << mce);
Expand Down
5 changes: 5 additions & 0 deletions testdata/p4_16_samples/issue3324.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void f<t>(in t a){ }
void g<t>(in t b)
{
f(b);
}
5 changes: 5 additions & 0 deletions testdata/p4_16_samples_outputs/issue3324-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void f<t>(in t a) {
}
void g<t>(in t b) {
f<t>(b);
}
Empty file.
5 changes: 5 additions & 0 deletions testdata/p4_16_samples_outputs/issue3324.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void f<t>(in t a) {
}
void g<t>(in t b) {
f(b);
}
1 change: 1 addition & 0 deletions testdata/p4_16_samples_outputs/issue3324.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[--Wwarn=missing] warning: Program does not contain a `main' module

0 comments on commit ecb2c7b

Please sign in to comment.