Bug Summary

File:jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp
Warning:line 78, column 26
Assigned value is garbage or undefined

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test_count_trailing_zeros.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/gtest/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/googletest/googletest/include -I /home/daniel/Projects/java/googletest/googlemock/include -I /home/daniel/Projects/java/jdk/test/hotspot/gtest -I /home/daniel/Projects/java/jdk/test/hotspot/gtest -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -Wno-undef -Wno-stringop-overflow -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp
1/*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#include "precompiled.hpp"
26#include "utilities/count_trailing_zeros.hpp"
27#include "utilities/globalDefinitions.hpp"
28#include "unittest.hpp"
29
30
31template <typename T> static void test_one_or_two_set_bits() {
32 unsigned i = 0; // Position of a set bit.
33 unsigned max = sizeof(T) * BitsPerByte;
34 for (T ix = T(1); i < max; ix <<= 1, ++i) {
35 unsigned j = 0; // Position of a set bit.
36 for (T jx = T(1); j < max; jx <<= 1, ++j) {
37 T value = ix | jx;
38 EXPECT_EQ(MIN2(i, j), count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(MIN2(i, j))) == 1)>::Compare
("MIN2(i, j)", "count_trailing_zeros(value)", MIN2(i, j), count_trailing_zeros
(value)))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 38, gtest_ar.failure_message()) = ::testing::Message()
39 << "value = " << value;
40 }
41 }
42}
43
44TEST(count_trailing_zeros, one_or_two_set_bits)class count_trailing_zeros_one_or_two_set_bits_Test : public ::
testing::Test { public: count_trailing_zeros_one_or_two_set_bits_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); count_trailing_zeros_one_or_two_set_bits_Test
(count_trailing_zeros_one_or_two_set_bits_Test const &) =
delete; void operator=(count_trailing_zeros_one_or_two_set_bits_Test
const &) = delete;};::testing::TestInfo* const count_trailing_zeros_one_or_two_set_bits_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"count_trailing_zeros", "one_or_two_set_bits", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 44), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< count_trailing_zeros_one_or_two_set_bits_Test
>);void count_trailing_zeros_one_or_two_set_bits_Test::TestBody
()
{
45 test_one_or_two_set_bits<int8_t>();
46 test_one_or_two_set_bits<int16_t>();
47 test_one_or_two_set_bits<int32_t>();
48 test_one_or_two_set_bits<int64_t>();
49 test_one_or_two_set_bits<uint8_t>();
50 test_one_or_two_set_bits<uint16_t>();
51 test_one_or_two_set_bits<uint32_t>();
52 test_one_or_two_set_bits<uint64_t>();
53}
54
55template <typename T> static void test_high_zeros_low_ones() {
56 T value = std::numeric_limits<T>::max();
57 for ( ; value != 0; value >>= 1) {
58 EXPECT_EQ(0u, count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u",
"count_trailing_zeros(value)", 0u, count_trailing_zeros(value
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 58, gtest_ar.failure_message()) = ::testing::Message()
59 << "value = " << value;
60 }
61}
62
63TEST(count_trailing_zeros, high_zeros_low_ones)class count_trailing_zeros_high_zeros_low_ones_Test : public ::
testing::Test { public: count_trailing_zeros_high_zeros_low_ones_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); count_trailing_zeros_high_zeros_low_ones_Test
(count_trailing_zeros_high_zeros_low_ones_Test const &) =
delete; void operator=(count_trailing_zeros_high_zeros_low_ones_Test
const &) = delete;};::testing::TestInfo* const count_trailing_zeros_high_zeros_low_ones_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"count_trailing_zeros", "high_zeros_low_ones", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 63), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< count_trailing_zeros_high_zeros_low_ones_Test
>);void count_trailing_zeros_high_zeros_low_ones_Test::TestBody
()
{
64 test_high_zeros_low_ones<int8_t>();
65 test_high_zeros_low_ones<int16_t>();
66 test_high_zeros_low_ones<int32_t>();
67 test_high_zeros_low_ones<int64_t>();
68 test_high_zeros_low_ones<uint8_t>();
69 test_high_zeros_low_ones<uint16_t>();
70 test_high_zeros_low_ones<uint32_t>();
71 test_high_zeros_low_ones<uint64_t>();
72}
73
74template <typename T> static void test_high_ones_low_zeros() {
75 unsigned i = 0; // Index of least significant set bit.
76 T value = ~T(0);
77 unsigned max = sizeof(T) * BitsPerByte;
78 for ( ; i < max; value <<= 1, ++i) {
2
Loop condition is true. Entering loop body
6
Assigned value is garbage or undefined
79 EXPECT_EQ(i, count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(i)) == 1)>::Compare("i", "count_trailing_zeros(value)"
, i, count_trailing_zeros(value)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 79, gtest_ar.failure_message()) = ::testing::Message()
3
Control jumps to 'case 0:' at line 79
4
Assuming the condition is true
5
Taking true branch
80 << "value = " << value;
81 }
82}
83
84TEST(count_trailing_zeros, high_ones_low_zeros)class count_trailing_zeros_high_ones_low_zeros_Test : public ::
testing::Test { public: count_trailing_zeros_high_ones_low_zeros_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); count_trailing_zeros_high_ones_low_zeros_Test
(count_trailing_zeros_high_ones_low_zeros_Test const &) =
delete; void operator=(count_trailing_zeros_high_ones_low_zeros_Test
const &) = delete;};::testing::TestInfo* const count_trailing_zeros_high_ones_low_zeros_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"count_trailing_zeros", "high_ones_low_zeros", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp"
, 84), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< count_trailing_zeros_high_ones_low_zeros_Test
>);void count_trailing_zeros_high_ones_low_zeros_Test::TestBody
()
{
85 test_high_ones_low_zeros<int8_t>();
1
Calling 'test_high_ones_low_zeros<signed char>'
86 test_high_ones_low_zeros<int16_t>();
87 test_high_ones_low_zeros<int32_t>();
88 test_high_ones_low_zeros<int64_t>();
89 test_high_ones_low_zeros<uint8_t>();
90 test_high_ones_low_zeros<uint16_t>();
91 test_high_ones_low_zeros<uint32_t>();
92 test_high_ones_low_zeros<uint64_t>();
93}