Open mihaibudiu opened 1 year ago
Shouldn't the existing -Werror
do the trick?
We don't issue warnings about undefined behaviors
If we can detect them, we probably should. In fact, that's one of the primary reasons for a warning. And then the user will have a choice whether to disable them (on a per-class basis or via NoWarn() annotation) or convert them into errors.
Note some undefined behaviors as defined in the spec can only be detected at runtime. E.g. accessing an invalid header might not be reachable normally. There might be other cases too. Now P4C warns about the accessing of an invalid header but I don't think P4C warns about all undefined at runtime though.
@apinski-cavium -- agreed.
Some backends also perform somewhat deeper analysis, but it is still not exhaustive.
I do not think that the goal is to create anything foolproof. It is just yet another useful tool that might be helpful to some people and what I am trying to do here is to suggest a mechanism (i.e. a warning), for which we already have several flexible policies to handle it further.
It would even be possible to insert run-time instrumentation to (sample and) send digest messages when undefined behaviors happen dynamically. Like out of bounds accesses to stacks.
The Cisco qfp routing asic is programmed in C. The C code is compiled with a Tensilica compiler which initializes every variable and pointer before generating firmware.
And it is easily possible to develop a P4 implementation that also initializes every variable to a deterministic value, e.g. 0, and nothing in the language spec disallows this. In most implementations, that will cost something extra, vs. an implementation that does not do so.
Perhaps the first thing to do here is to define the user interface.
Should it be just --strict
or do we want to require e.g. --strict=on
and/or --strict=yes
?
Are we planning on having different levels of strictness, such that e.g. --strictness=1
, --strictness=2
, and --strictness=3
all make sense at least in the context of one particular back-end?
Here is a quote from the current spec, appendix G:
This is probably a matter of implementation rather than spec. It would be nice if the compiler had a flag which would cause it to reject code that has undefined behaviors.