Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow casts int to int #3220

Merged
merged 2 commits into from
Apr 15, 2022
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
4 changes: 3 additions & 1 deletion frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,9 @@ bool TypeInference::canCastBetween(const IR::Type* dest, const IR::Type* src) co
return b->size == 1 && !b->isSigned;
}
} else if (src->is<IR::Type_InfInt>()) {
return dest->is<IR::Type_Bits>() || dest->is<IR::Type_Boolean>();
return dest->is<IR::Type_Bits>() ||
dest->is<IR::Type_Boolean>() ||
dest->is<IR::Type_InfInt>();
} else if (src->is<IR::Type_Newtype>()) {
auto st = getTypeType(src->to<IR::Type_Newtype>()->type);
return typeMap->equivalent(dest, st);
Expand Down
19 changes: 19 additions & 0 deletions testdata/p4_16_samples/issue3219.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
bit<4> func1() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this a test that produces an output? We'll see whether Gauntlet needs fixing..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

bit<4> t = (int)1;
return t;
}

bit<4> func2() {
bit<4> t = (bit<4>)(int)(bit<4>)1;
return t;
}

control c(out bit<4> result) {
apply {
result = func1();
}
}
control _c(out bit<4> r);
package top(_c _c);

top(c()) main;
18 changes: 18 additions & 0 deletions testdata/p4_16_samples_outputs/issue3219-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bit<4> func1() {
bit<4> t = (bit<4>)(int)1;
return t;
}
bit<4> func2() {
bit<4> t = (bit<4>)(int)4w1;
return t;
}
control c(out bit<4> result) {
apply {
result = func1();
}
}

control _c(out bit<4> r);
package top(_c _c);
top(c()) main;

17 changes: 17 additions & 0 deletions testdata/p4_16_samples_outputs/issue3219-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
control c(out bit<4> result) {
@name("c.hasReturned") bool hasReturned;
@name("c.retval") bit<4> retval;
@name("c.t") bit<4> t_0;
apply {
hasReturned = false;
t_0 = (bit<4>)(int)1;
hasReturned = true;
retval = t_0;
result = retval;
}
}

control _c(out bit<4> r);
package top(_c _c);
top(c()) main;

19 changes: 19 additions & 0 deletions testdata/p4_16_samples_outputs/issue3219-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
control c(out bit<4> result) {
@hidden action issue3219l13() {
result = (bit<4>)(int)1;
}
@hidden table tbl_issue3219l13 {
actions = {
issue3219l13();
}
const default_action = issue3219l13();
}
apply {
tbl_issue3219l13.apply();
}
}

control _c(out bit<4> r);
package top(_c _c);
top(c()) main;

18 changes: 18 additions & 0 deletions testdata/p4_16_samples_outputs/issue3219.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bit<4> func1() {
bit<4> t = (int)1;
return t;
}
bit<4> func2() {
bit<4> t = (bit<4>)(int)(bit<4>)1;
return t;
}
control c(out bit<4> result) {
apply {
result = func1();
}
}

control _c(out bit<4> r);
package top(_c _c);
top(c()) main;

Empty file.