On Fri, 2021-06-11 at 10:37 +0100, Jonny Grant wrote: > Hello > This isn't real code, it's just an example to ask this question: > > Would GCC optimizer ever re-order these statements and cause a NULL ptr > de-reference SIGSEGV? I recall reading a Chris Lattner paper indicating > it could happen. > > void f(int * p) > { > if(!p) > { > return; > } > > printf("%d\n", *p); > } No it won't. What Chris paper says is about something like: void f(int * p) { int x = *p; if(!p) { return; } printf("%d\n", x); } if p is NULL, this is an UB and the compiler can do anything. -- Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University