svn commit: r328159 - head/sys/modules

Mark Millard marklmi26-fbsd at yahoo.com
Sat Jan 20 01:11:03 UTC 2018


Conrad Meyer cem at freebsd.org wrote on
Fri Jan 19 05:07:22 UTC 2018 :

> The spec says the behavior is undefined; not that the compiler has to
> produce a warning or error message.  The compiler *does* get to
> arbitrarily decide what it wants to do when it encounters UB.  It is
> wholly free to implement this particular UB with the logical result
> and no warning/error.

This is partially correct and partially probably-not, at least
for C99.

6.5.7 of C99 does say the constraint and the undefined
status that results for the left shift issue in question
(and the right shift for that matter):

"If the value of the right operand is negative or is greater than
or equal to the width of the promoted left operand, the behavior
is undefined."

But 5.1.1.3 says about Diagnostics:

"A conforming implementation shall produce at least one diagnostic message
(identified in an implementation-defined manner) if a preprocessing
translation unit or translation unit contains a violation of any syntax
rule or constraint, even if the behavior is also explicitly specified as
undefined or implementation-defined."

The relevant part of 6.5.7 from what I quoted does specify a "constraint"
with undefined behavior, section 3.8 defines "constraint" via:

"restriction, either syntactic or semantic, by which the exposition of
language elements is to be interpreted"

Notes:

My stated view presumes that known compile-time-constants are to be
checked at compile time for constraint violations but proving absence
of run-time problems is not to be done at compile time.

The difference between "diagnostic" and the more specific
alternatives "warning" and "error" leave some room that I
ignore here.



===
Mark Millard
marklmi at yahoo.com
( markmi at dsl-only.net is
going away in 2018-Feb, late)



More information about the svn-src-head mailing list