Comment
Comment by ndriscoll
You know that compilers can elide checks if it's a provably impossible case, right? So they could have checks in both places in the source code. Or I know that I was using static_assert in C on sizes of buffers/messages in my parsers for fibre channel firmware at IBM 10 years ago, and I'm like 99% certain clang static analyzer would do that kind of "what if this is too small" analysis across functions back then. You can also use e.g. phantom types or just like... structs/classes to enforce invariants (e.g. that it's been checked; your check four layers up could've been an inlined constructor of a trivial struct doing validation) purely at compile time. You can't infer what the actual source looks like at all based on disassembly.