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

Do not print confusing warning when a parser state contains an assignment to an l-value slice #4948

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions midend/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,13 @@ void ExpressionEvaluator::postorder(const IR::Operation_Ternary *expression) {
auto e1i = e1->to<ScalarValue>();
auto e2i = e2->to<ScalarValue>();
if (e0i->isUninitialized()) {
auto result = new SymbolicStaticError(expression->e0, "Uninitialized");
set(expression, result);
return;
// This cannot be an uninitialized read if 'expression' is the LHS of
// an assignment to a sliced l-value.
if (!evaluatingLeftValue) {
auto result = new SymbolicStaticError(expression->e0, "Uninitialized");
set(expression, result);
return;
}
} else if (e1i->isUninitialized()) {
auto result = new SymbolicStaticError(expression->e1, "Uninitialized");
set(expression, result);
Expand Down
12 changes: 12 additions & 0 deletions testdata/p4_16_samples/parser-unroll-uninitialized-slice-read.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
16 changes: 16 additions & 0 deletions testdata/p4_16_samples/parser-unroll-uninitialized-slice-write.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parser-unroll-uninitialized-slice-read.p4(5): [--Wwarn=uninitialized_use] warning: f may be uninitialized
g = f[3:0];
^
parser-unroll-uninitialized-slice-read.p4(3): [--Wwarn=uninitialized_out_param] warning: out parameter 'f' may be uninitialized when 'p' terminates
parser p(packet_in packet, out bit<8> f, out bit<4> g) {
^
parser-unroll-uninitialized-slice-read.p4(3)
parser p(packet_in packet, out bit<8> f, out bit<4> g) {
^
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parser-unroll-uninitialized-slice-write.p4(9): [--Wwarn=uninitialized_use] warning: s.f may be uninitialized
s.f[3:0] = 2;
^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core.p4>

parser p(packet_in packet, out bit<8> f, out bit<4> g) {
state start {
g = f[3:0];
transition accept;
}
}

parser simple(packet_in packet, out bit<8> f, out bit<4> g);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parser-unroll-uninitialized-slice-read.p4(5): [--Wwarn=uninitialized_use] warning: f may be uninitialized
g = f[3:0];
^
parser-unroll-uninitialized-slice-read.p4(3): [--Wwarn=uninitialized_out_param] warning: out parameter 'f' may be uninitialized when 'p' terminates
parser p(packet_in packet, out bit<8> f, out bit<4> g) {
^
parser-unroll-uninitialized-slice-read.p4(3)
parser p(packet_in packet, out bit<8> f, out bit<4> g) {
^
parser-unroll-uninitialized-slice-read.p4(5): [--Wwarn=ignore-prop] warning: Result of 'g = f[3:0]' is not defined: Error: Uninitialized
g = f[3:0];
^
Comment on lines +10 to +12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that this warning is worded this way is not great - I opened #4945 to improve this and similar warnings

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 4w2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <core.p4>

struct S {
bit<8> f;
}

parser p(packet_in packet, out S s) {
state start {
s.f[3:0] = 2;
transition accept;
}
}

parser simple(packet_in packet, out S s);
package top(simple e);
top(p()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parser-unroll-uninitialized-slice-write.p4(9): [--Wwarn=uninitialized_use] warning: s.f may be uninitialized
s.f[3:0] = 2;
^^^
Loading