8198304: VS2017 (C4838, C4312) Various conversion issues with gtest tests
authorlfoltan
Mon, 26 Feb 2018 10:11:05 -0500
changeset 49167 ba9da6aaae36
parent 49166 2879dad8d4ec
child 49168 23348e42fb34
8198304: VS2017 (C4838, C4312) Various conversion issues with gtest tests Summary: Introduce specific casts to fix multiple type cast conversion compilation errors. Reviewed-by: gtriantafill, hseigel
test/hotspot/gtest/memory/test_guardedMemory.cpp
test/hotspot/gtest/utilities/test_align.cpp
--- a/test/hotspot/gtest/memory/test_guardedMemory.cpp	Mon Feb 26 09:57:01 2018 -0500
+++ b/test/hotspot/gtest/memory/test_guardedMemory.cpp	Mon Feb 26 10:11:05 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,8 @@
 #include "runtime/os.hpp"
 #include "unittest.hpp"
 
+#define GEN_PURPOSE_TAG ((void *) ((uintptr_t)0xf000f000))
+
 static void guarded_memory_test_check(void* p, size_t sz, void* tag) {
   ASSERT_TRUE(p != NULL) << "NULL pointer given to check";
   u_char* c = (u_char*) p;
@@ -60,7 +62,7 @@
 TEST(GuardedMemory, basic) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   EXPECT_EQ(badResourceValue, *basep)
           << "Expected guard in the form of badResourceValue";
@@ -68,7 +70,7 @@
   u_char* userp = guarded.get_user_ptr();
   EXPECT_EQ(uninitBlockPad, *userp)
           << "Expected uninitialized data in the form of uninitBlockPad";
-  guarded_memory_test_check(userp, 1, (void*) 0xf000f000);
+  guarded_memory_test_check(userp, 1, GEN_PURPOSE_TAG);
 
   void* freep = guarded.release_for_freeing();
   EXPECT_EQ((u_char*) freep, basep) << "Expected the same pointer guard was ";
@@ -81,7 +83,7 @@
 TEST(GuardedMemory, odd_sizes) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   size_t sz = 0;
   do {
@@ -102,7 +104,7 @@
 TEST(GuardedMemory, buffer_overrun_head) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   guarded.wrap_with_guards(basep, 1);
   *basep = 0;
@@ -114,7 +116,7 @@
 TEST(GuardedMemory, buffer_overrun_tail) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   size_t sz = 1;
   do {
--- a/test/hotspot/gtest/utilities/test_align.cpp	Mon Feb 26 09:57:01 2018 -0500
+++ b/test/hotspot/gtest/utilities/test_align.cpp	Mon Feb 26 10:11:05 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,7 @@
 #include <limits>
 
 // A few arbitrarily chosen values to test the align functions on.
-static uint64_t values[] = {1, 3, 10, 345, 1023, 1024, 1025, 23909034, INT_MAX, uint64_t(-1) / 2, uint64_t(-1) / 2 + 100, -1 };
+static uint64_t values[] = {1, 3, 10, 345, 1023, 1024, 1025, 23909034, INT_MAX, uint64_t(-1) / 2, uint64_t(-1) / 2 + 100, uint64_t(-1)};
 
 template <typename T>
 static T max_alignment() {