Date: Fri, 19 Jan 2018 17:10:49 -0800 From: Mark Millard <marklmi26-fbsd@yahoo.com> To: "Conrad E. Meyer" <cem@freebsd.org>, bjkfbsd@gmail.com, svn-src-head@freebsd.org Subject: Re: svn commit: r328159 - head/sys/modules Message-ID: <837BD7D7-63C9-4C87-AFCB-DE6CC2591011@yahoo.com>
next in thread | raw e-mail | index | archive | help
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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?837BD7D7-63C9-4C87-AFCB-DE6CC2591011>