Il 08/03/2013 01:14, Andrew Fish ha scritto: > We just ran into an issue that I thought was worth sharing with the > group. We just updated our compiler and a memory test got optimized > away. At first we thought it was a compiler bug. But then we were > informed that in the C language the dereference of a NULL pointer is > undefined behavior. So technically it is legal for the compiler to > optimize it way. > > So to be pedantic in C if you ever dereference a NULL point on > purpose you need to make it a volatile to conform to the C standard. > A memory test may want to access address 0, and code that writes the > ARM or 8086 vector table may also end up dereferencing a NULL > pointer. > > I think folks will find Chris Lattner's blog interesting > http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
Do you know what MSVC does about this? For GCC/clang, it is probably best to add -fno-delete-null-pointer-checks to the command line, because a NULL pointer dereference will not cause abnormal termination in TianoCore. The Linux kernel uses the same option. Paolo ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
