pub struct Wrapping {
pub signed: bool,
pub pointer: bool,
pub trap: bool,
}Expand description
What overflows rather than being undefined, from -fwrapv and its relatives.
C says a signed addition that overflows and a pointer that walks off the end of the object it points into are both undefined, and an optimizer that believes it reads a great deal into every loop: that a counter going up one at a time never turns round, that an index widened to an address may be widened before the arithmetic rather than after, that a bound is reached. These flags withdraw exactly that. They do not make the program mean something else, they make it mean less, and the code that asks for them is code that overflows on purpose and wants the answer the machine gives rather than the answer the standard declines to give.
Two of them because gcc has two, and a build that wants one usually wants the other. Signed arithmetic and pointer arithmetic are separate assumptions and a kernel turns both off.
-ftrapv is the third answer to the first question and is here for that reason. Undefined,
wrapping and stopping are the three things a signed overflow can be, and a command line picks
one of them: the last of -fwrapv and -ftrapv wins, which is gcc’s behaviour and what makes
them one field rather than two that can both be set.
Fields§
§signed: boolWhether signed arithmetic wraps, from -fwrapv.
pointer: boolWhether pointer arithmetic wraps, from -fwrapv-pointer.
trap: boolWhether a signed overflow stops the program instead, from -ftrapv.
Never set at the same time as Wrapping::signed, since a program cannot both wrap and
stop, and the driver is what keeps that true by clearing each when the other is asked for.
Implementations§
Source§impl Wrapping
impl Wrapping
Sourcepub const ALL: Self
pub const ALL: Self
Both of them, which is what -fno-strict-overflow asks for.
gcc says so itself: its help text for -fstrict-overflow reads “negated as -fwrapv
-fwrapv-pointer”, so the older flag is a name for the pair rather than a third knob. And
asking for wrapping is asking for not stopping, so this is the whole answer and not two
thirds of one.