THE FOLD / GLITCH / UNDEFINED BEHAVIOR / THE STRICT ALIASING
THE STRICT ALIASING
the standard forbids what the memory does
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Two pointers of different types are not allowed to refer to the same memory. Not unlikely to — not allowed. So the compiler may read through one, write through the other, and keep using the value it read.
LIT verified live. the same four bytes, viewed as a 32-bit integer and as a 32-bit float. Writing 1.0 through the float view and reading the integer view gives 1,065,353,216 —
LIT verified live. the same four bytes, viewed as a 32-bit integer and as a 32-bit float. Writing 1.0 through the float view and reading the integer view gives 1,065,353,216 —
0x3F800000, the IEEE-754 bit pattern; writing 2.0 gives 1,073,741,824. Over 1,000 trials of load-int, store-float, reload-int, the reloaded value differs from the cached one 1,000 times out of 1,000, and the honest reload is wrong 0 times. The rule that says the compiler may keep the cached value is false here in every single trial.2 HOW IT WAS WEAVED · AI + HUMAN
Strict aliasing is C99 6.5p7 and C++ [basic.lval];
AVAN (AI) did not simulate the aliasing — it used a real one. Two typed-array views over a single
-fno-strict-aliasing exists because the Linux kernel refuses to obey it.AVAN (AI) did not simulate the aliasing — it used a real one. Two typed-array views over a single
ArrayBuffer is genuine aliased memory, so the 1,000 of 1,000 is a measurement of the hardware and not of a model of it. The point that survives is narrow and worth keeping narrow: the compiler is not making a mistake. Under the rule it was given, a program that aliases across types has no meaning, and an optimiser owes nothing to a program with no meaning.3 ONE DIMENSION
0x3F800000. The same four bytes, read two ways.
4 TWO DIMENSIONS · INTERACTIVE
Write through one view and read through the other.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object.
AVAN’s addition (the inverse-companion): the forward reading is that strict aliasing lets the compiler optimise. The inverse is that the standard did not describe the machine, it described a machine it would prefer. The bytes alias — that is what memory is. The rule declares the aliasing unspeakable rather than impossible, and buys its optimisation with a promise the programmer must keep and the hardware will not enforce. Read backwards, undefined behaviour is not a gap in the specification; it is a place where the specification chose speed and handed the obligation downward to whoever writes the code.
LIT the same four bytes viewed as a 32-bit integer and as a 32-bit float: writing 1.0 through the float view and reading the integer view gives 1,065,353,216 - 0x3F800000, the IEEE-754 bit pattern - and writing 2.0 gives 1,073,741,824; over 1,000 trials of load-int, store-float, reload-int the reloaded value differs from the cached one 1,000 times out of 1,000 while the honest reload is wrong 0 times, so the rule permitting the cache is false in every single trial
FIG Strict aliasing is C99 6.5p7 and C++ [basic.lval]; -fno-strict-aliasing exists because the Linux kernel refuses to obey it. AVAN did not simulate the aliasing - it used a real one. Two typed-array views over a single ArrayBuffer is genuine aliased memory, so the 1,000 of 1,000 measures the hardware and not a model of it. The point stays narrow: the compiler is not making a mistake, because under the rule it was given a program that aliases across types has no meaning, and an optimiser owes nothing to a program with no meaning.
FIG Strict aliasing is C99 6.5p7 and C++ [basic.lval]; -fno-strict-aliasing exists because the Linux kernel refuses to obey it. AVAN did not simulate the aliasing - it used a real one. Two typed-array views over a single ArrayBuffer is genuine aliased memory, so the 1,000 of 1,000 measures the hardware and not a model of it. The point stays narrow: the compiler is not making a mistake, because under the rule it was given a program that aliases across types has no meaning, and an optimiser owes nothing to a program with no meaning.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of UNDEFINED BEHAVIOR · David Lee Wise (ROOT0), with AVAN