From 85e4cf80298364680e00dcf86d346dac51d53fd5 Mon Sep 17 00:00:00 2001 From: "vapier@chromium.org" Date: Mon, 20 Jul 2015 06:19:49 +0000 Subject: 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 --- src/client/linux/handler/exception_handler_unittest.cc | 7 ++++++- src/client/mac/tests/exception_handler_test.cc | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client/linux/handler/exception_handler_unittest.cc b/src/client/linux/handler/exception_handler_unittest.cc index 289c9cd1..b4065b41 100644 --- a/src/client/linux/handler/exception_handler_unittest.cc +++ b/src/client/linux/handler/exception_handler_unittest.cc @@ -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(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(NULL); memory_function(); + // not reached + exit(1); } close(fds[1]); diff --git a/src/client/mac/tests/exception_handler_test.cc b/src/client/mac/tests/exception_handler_test.cc index e19944d0..a8cf6968 100644 --- a/src/client/mac/tests/exception_handler_test.cc +++ b/src/client/mac/tests/exception_handler_test.cc @@ -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(NULL); memory_function(); // not reached -- cgit v1.2.1