Three proposals for the C standard WG14
&gt; <i>6. EXAMPLE Code that checks to see if a pointer value is null cannot be omitted during translation solely on the basis that the pointer is dereferenced before the check and that earlier dereference would produce undefined behavior if the pointer value was null.</i><p>Here&#x27;s the thing I don&#x27;t quite understand: I gather that this is advocating for something like GCC&#x27;s -fno-delete-null-pointer-checks to be part of the spec, but, how is -fno-delete-null-pointer-checks actually helpful?<p>I <i>think</i> it&#x27;s because if you write code like this:<p><pre><code>    void foo(struct foo *param) {
        int n = param-&gt;length, i;
    
        if (param == NULL) {
            return;
        }
    
        for (i = 0; i &lt; n; i++) {
            do_something(param-&gt;data[i]);
        }
    }
</code></pre>
with -fdelete-null-pointer-checks the compiler might optimize it in two successive steps to delete the check (because param-&gt;length was already dereferenced) and then move the dereference down to the beginning of the for loop, and with -fno-delete-null-pointer-checks the compiler might skip the first optimization and keep the second.<p>But for -fno-delete-null-pointer-checks, you&#x27;re relying on the second optimization, moving the dereference later. Otherwise you&#x27;d just have segfaulted already (or, in a kernel context, the read might have <i>succeeded</i> from a userspace page mapped at the null page). Right?<p>It seems reasonable for the compiler (or some other tool) to produce a hard error here and prevent this code from compiling, saying, hey, this is clearly doing something unwanted. It doesn&#x27;t seem reasonable to expect the compiler to do certain optimizations to make your code safe, <i>without</i> which your code would have a security vulnerability, and also get mad at the compiler for doing more optimizations that return it to the original state of things.<p>&gt; <i>The limitation of lvalue access by types has never made much sense and required a undefensible exception for character pointers.</i><p>My understanding of type-based alias analysis is that it&#x27;s required for code like this to optimize the way you&#x27;d want:<p><pre><code>    struct string {
        size_t len;
        char *data;
    }

    void copy_string(struct string *dest, struct string *src) {
        size_t i;
        if (dest-&gt;len &lt; src-&gt;len) return;
        for (i = 0; i &lt; src-&gt;len; i++) {
            dest-&gt;data[i] = src-&gt;data[i];
        }
    }
</code></pre>
Otherwise the compiler would have to worry that dest-&gt;data would overlap with src-&gt;len and re-read it every time!<p>You can do this without type-based alias analysis in a language that gave you different tools for managing variables, but doing so backwards-compatibly in C seems difficult, and this proposed rule does not seem to help.