tests: InstructionPointerMemoryNullPointer: make it work under llvm

When LLVM sees an attempt to dereference a NULL pointer, it will generate
invalid opcodes (undefined behavior) which leads to SIGILL which breaks
this unittest.  Upstream's recommendation in this case is to add volatile
markings to get the actual dereference to happen.

This is documented in the blog post under "Dereferencing a NULL Pointer":
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1473 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
vapier@chromium.org 2015-07-20 06:19:49 +00:00
parent a840e1b710
commit 85e4cf8029
2 changed files with 9 additions and 2 deletions

View file

@ -774,8 +774,13 @@ TEST(ExceptionHandlerTest, InstructionPointerMemoryNullPointer) {
true, -1);
// Try calling a NULL pointer.
typedef void (*void_function)(void);
void_function memory_function = reinterpret_cast<void_function>(NULL);
// Volatile markings are needed to keep Clang from generating invalid
// opcodes. See http://crbug.com/498354 for details.
volatile void_function memory_function =
reinterpret_cast<void_function>(NULL);
memory_function();
// not reached
exit(1);
}
close(fds[1]);

View file

@ -610,7 +610,9 @@ TEST_F(ExceptionHandlerTest, InstructionPointerMemoryNullPointer) {
ExceptionHandler eh(tempDir.path(), NULL, MDCallback, &fds[1], true, NULL);
// Try calling a NULL pointer.
typedef void (*void_function)(void);
void_function memory_function =
// Volatile markings are needed to keep Clang from generating invalid
// opcodes. See http://crbug.com/498354 for details.
volatile void_function memory_function =
reinterpret_cast<void_function>(NULL);
memory_function();
// not reached