summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-04-22 19:18:31 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-22 19:18:31 -0700
commit14f5aeb5a46f330bd9386cd698fa25da3775d909 (patch)
tree75c97c17bedf5ba4f35899d06620d28b28ef7510 /core/fxcrt
parent90c964fb069bfa9934493481f8ccfefef9c3b3fe (diff)
downloadpdfium-14f5aeb5a46f330bd9386cd698fa25da3775d909.tar.xz
Change the code to avoid three unit test failures on release build
We have three failed unit tests -- FX_AllocOverflow(), FX_AllocOverflow2D(), and FX_TryAllocOverflow() on Linux and Mac release builds, because Clang aggressively optimizes the code. Adding some usage of the return value of a function can avoid the function being optimized away by Clang. Review URL: https://codereview.chromium.org/1915693002
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_basic_memmgr_unittest.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/core/fxcrt/fx_basic_memmgr_unittest.cpp b/core/fxcrt/fx_basic_memmgr_unittest.cpp
index f69b1325dc..3ce533012f 100644
--- a/core/fxcrt/fx_basic_memmgr_unittest.cpp
+++ b/core/fxcrt/fx_basic_memmgr_unittest.cpp
@@ -29,17 +29,24 @@ TEST(fxcrt, DISABLED_FX_AllocOOM) {
}
TEST(fxcrt, FX_AllocOverflow) {
- EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc(int, kOverflowIntAlloc), "");
+ // |ptr| needs to be defined and used to avoid Clang optimizes away the
+ // FX_Alloc() statement overzealously for optimized builds.
+ int* ptr = nullptr;
+ EXPECT_DEATH_IF_SUPPORTED(ptr = FX_Alloc(int, kOverflowIntAlloc), "") << ptr;
- int* ptr = FX_Alloc(int, 1);
+ ptr = FX_Alloc(int, 1);
EXPECT_TRUE(ptr);
EXPECT_DEATH_IF_SUPPORTED((void)FX_Realloc(int, ptr, kOverflowIntAlloc), "");
FX_Free(ptr);
}
TEST(fxcrt, FX_AllocOverflow2D) {
- EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D),
- "");
+ // |ptr| needs to be defined and used to avoid Clang optimizes away the
+ // FX_Alloc() statement overzealously for optimized builds.
+ int* ptr = nullptr;
+ EXPECT_DEATH_IF_SUPPORTED(ptr = FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D),
+ "")
+ << ptr;
}
TEST(fxcrt, DISABLED_FX_TryAllocOOM) {
@@ -52,9 +59,12 @@ TEST(fxcrt, DISABLED_FX_TryAllocOOM) {
}
TEST(fxcrt, FX_TryAllocOverflow) {
- EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc));
+ // |ptr| needs to be defined and used to avoid Clang optimizes away the
+ // calloc() statement overzealously for optimized builds.
+ int* ptr = (int*)calloc(sizeof(int), kOverflowIntAlloc);
+ EXPECT_FALSE(ptr) << ptr;
- int* ptr = FX_Alloc(int, 1);
+ ptr = FX_Alloc(int, 1);
EXPECT_TRUE(ptr);
EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
FX_Free(ptr);