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

Add temporary IR nodes to typeMap #2972

Merged
merged 1 commit into from
Dec 1, 2021
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
29 changes: 17 additions & 12 deletions frontends/p4/simplifyDefUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,10 @@ class FindUninitialized : public Inspector {
if (auto list = src->to<IR::StructExpression>()) {
auto it = list->components.begin();
for (auto field : dst_struct->fields) {
IR::Member member(dst, field->name);
processHeadersInAssignment(&member, (*it)->expression,
typeMap->getType(field, true),
auto ftype = typeMap->getType(field, true);
auto member = new IR::Member(dst, field->name);
typeMap->setType(member, ftype);
processHeadersInAssignment(member, (*it)->expression, ftype,
typeMap->getType((*it)->expression, true));
++it;
}
Expand All @@ -727,11 +728,12 @@ class FindUninitialized : public Inspector {
}
} else if (src_type->to<IR::Type_Struct>()) {
for (auto field : dst_struct->fields) {
IR::Member dst_member(dst, field->name);
IR::Member src_member(src, field->name);
processHeadersInAssignment(&dst_member, &src_member,
typeMap->getType(field, true),
typeMap->getType(field, true));
auto ftype = typeMap->getType(field, true);
auto dst_member = new IR::Member(dst, field->name);
auto src_member = new IR::Member(src, field->name);
typeMap->setType(dst_member, ftype);
typeMap->setType(src_member, ftype);
processHeadersInAssignment(dst_member, src_member, ftype, ftype);
}
} else {
BUG("%1%: unexpected expression on RHS", src);
Expand All @@ -752,11 +754,14 @@ class FindUninitialized : public Inspector {
false;

for (auto field : dst_headerunion->fields) {
IR::Member dst_member(dst, field->name);
IR::Member src_member(src, field->name);
auto valid = headerDefs->find(&src_member);
auto ftype = typeMap->getType(field, true);
auto dst_member = new IR::Member(dst, field->name);
auto src_member = new IR::Member(src, field->name);
typeMap->setType(dst_member, ftype);
typeMap->setType(src_member, ftype);
auto valid = headerDefs->find(src_member);
if (!non_constant_indexing || valid == TernaryBool::Yes)
headerDefs->update(headerDefs->getStorageLocation(&dst_member),
headerDefs->update(headerDefs->getStorageLocation(dst_member),
valid);
}
auto valid = headerDefs->find(src);
Expand Down
29 changes: 29 additions & 0 deletions testdata/p4_16_samples/issue2958.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <core.p4>

header ethernet_t {
bit<48> dst_addr;
}

struct G {
ethernet_t eth;
}

struct H {
G g;
}

struct Headers {
ethernet_t eth_hdr;
}

control ingress(inout Headers h) {
H tmp = { { { 1 } } };

apply {
tmp.g.eth.dst_addr = 1;
}
}

control Ingress(inout Headers hdr);
package top(Ingress ig);
top(ingress()) main;
29 changes: 29 additions & 0 deletions testdata/p4_16_samples_outputs/issue2958-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <core.p4>

header ethernet_t {
bit<48> dst_addr;
}

struct G {
ethernet_t eth;
}

struct H {
G g;
}

struct Headers {
ethernet_t eth_hdr;
}

control ingress(inout Headers h) {
H tmp = (H){g = (G){eth = (ethernet_t){dst_addr = 48w1}}};
apply {
tmp.g.eth.dst_addr = 48w1;
}
}

control Ingress(inout Headers hdr);
package top(Ingress ig);
top(ingress()) main;

27 changes: 27 additions & 0 deletions testdata/p4_16_samples_outputs/issue2958-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <core.p4>

header ethernet_t {
bit<48> dst_addr;
}

struct G {
ethernet_t eth;
}

struct H {
G g;
}

struct Headers {
ethernet_t eth_hdr;
}

control ingress(inout Headers h) {
apply {
}
}

control Ingress(inout Headers hdr);
package top(Ingress ig);
top(ingress()) main;

27 changes: 27 additions & 0 deletions testdata/p4_16_samples_outputs/issue2958-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <core.p4>

header ethernet_t {
bit<48> dst_addr;
}

struct G {
ethernet_t eth;
}

struct H {
G g;
}

struct Headers {
ethernet_t eth_hdr;
}

control ingress(inout Headers h) {
apply {
}
}

control Ingress(inout Headers hdr);
package top(Ingress ig);
top(ingress()) main;

29 changes: 29 additions & 0 deletions testdata/p4_16_samples_outputs/issue2958.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <core.p4>

header ethernet_t {
bit<48> dst_addr;
}

struct G {
ethernet_t eth;
}

struct H {
G g;
}

struct Headers {
ethernet_t eth_hdr;
}

control ingress(inout Headers h) {
H tmp = { { { 1 } } };
apply {
tmp.g.eth.dst_addr = 1;
}
}

control Ingress(inout Headers hdr);
package top(Ingress ig);
top(ingress()) main;

Empty file.