From aca3d2c1c2cac957f4232c2feaf529387ef7fcb6 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 14 Apr 2011 19:36:05 +0000 Subject: fixes a problem caused by gcc 4.6 optimization (by Paul Pluzhnikov) git-svn-id: http://googletest.googlecode.com/svn/trunk@571 861a406c-534a-0410-8894-cb66d6ee9925 --- include/gtest/internal/gtest-port.h | 7 +++++++ src/gtest-death-test.cc | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index d2bc6cb..c6d102a 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -662,6 +662,13 @@ # define GTEST_API_ #endif +#if defined(__GNUC__) +// Ask the compiler to never inline a given function. +#define GTEST_NO_INLINE_ __attribute__((noinline)) +#else +#define GTEST_NO_INLINE_ +#endif // __GNUC__ + namespace testing { class Message; diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 603fccc..8b2e413 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -932,6 +932,11 @@ static int ExecDeathTestChildMain(void* child_arg) { // This could be accomplished more elegantly by a single recursive // function, but we want to guard against the unlikely possibility of // a smart compiler optimizing the recursion away. +// +// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining +// StackLowerThanAddress into StackGrowsDown, which then doesn't give +// correct answer. +bool StackLowerThanAddress(const void* ptr) GTEST_NO_INLINE_; bool StackLowerThanAddress(const void* ptr) { int dummy; return &dummy < ptr; -- cgit v1.2.1