Open Trigary opened 7 months ago
This was also introduced by e60cb8a633e305a75cb28c56dbd3d1dbccc871c8 (along with #4500, #4507, #4548).
e60cb8a633e305a75cb28c56dbd3d1dbccc871c8 added a second SimplifyDefUse
pass, which sees the following transformed IR:
apply {
hasReturned = false;
if (standard_metadata.ingress_global_timestamp == 48w123) {
hasReturned = true;
}
if (hasReturned) {
;
} else {
x_0 = 32w42;
if (standard_metadata.packet_length == 32w456) {
hasReturned = true;
}
}
if (hasReturned) {
;
} else {
log_msg<tuple<bit<32>>>("test {}", { x_0 });
}
}
whereas the first pass sees:
apply {
if (standard_metadata.ingress_global_timestamp == 48w123) {
return;
}
x_0 = 32w42;
if (standard_metadata.packet_length == 32w456) {
return;
}
log_msg<tuple<bit<32>>>("test {}", { x_0 });
}
The IR looks correct, but SimplifyDefUse
, which emits the warning, is probably not able to determine that x_0
is guaranteed to be initialized when hasReturned
is false.
Compiling the following code:
Results in the following warning, which I believe is incorrect behaviour:
The warning persists if I replace exactly one
return
withexit
, but the warning disappears if I replace both. The warning also disappears if I use a constant as theif
statement condition (e.g.if (true) return;
), this is why I used thosestandard_metadata
related checks in the sample above.p4c version:
1.2.4.2
These warnings were not present in the last p4c version I used, which I believe was
1.2.3.0
or1.2.2.0
.I attached the full source file for your convenience: switch.zip