On Tue 1/6/2026 5:08 AM, Waldek Hebisch wrote:
I get the following assembly:
00000000 <read_at0>:
0: b108 cbz r0, 6 <read_at0+0x6>
2: 2000 movs r0, #0
4: 4770 bx lr
6: 6803 ldr r3, [r0, #0]
8: deff udf #255 @ 0xff
a: bf00 nop
So compiler generates actiual access, but then, instead of returning
the value it executes undefined opcode. Without test for null
pointer I get simple access to memory.
When it comes to invalid (or missing, in C++) `return` statements, GCC
tends to adhere to a "punitive" approach in optimized code - it injects instructions to deliberately cause a crash/segfault in such cases.
Clang on the other hand tends to stick to the uniform approach based on
the "UB cannot happen" methodology, i.e. your code sample would be
translated under "p is never null" assumption, and the function will
fold into a simple unconditional `return 0`.
--
Best regards,
Andrey
--- PyGate Linux v1.5.2
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)