Bug Summary

File:jdk/test/hotspot/gtest/logging/test_logStream.cpp
Warning:line 81, column 17
Value stored to 'to_write' during its initialization is never read

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_logStream.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/logging/test_logStream.cpp
1/*
2 * Copyright (c) 2016, 2021, 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#include "precompiled.hpp"
25#include "jvm.h"
26#include "logTestFixture.hpp"
27#include "logTestUtils.inline.hpp"
28#include "logging/log.hpp"
29#include "logging/logStream.hpp"
30#include "unittest.hpp"
31
32class LogStreamTest : public LogTestFixture {
33 protected:
34 void verify_stream(outputStream* stream);
35};
36
37void LogStreamTest::verify_stream(outputStream* stream) {
38 set_log_config(TestLogFileName, "gc=debug");
39 stream->print("%d ", 3);
40 stream->print("workers");
41 stream->cr();
42 EXPECT_TRUE(file_contains_substring(TestLogFileName, "3 workers\n"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(file_contains_substring
(TestLogFileName, "3 workers\n"))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 42, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "file_contains_substring(TestLogFileName, \"3 workers\\n\")"
, "false", "true").c_str()) = ::testing::Message()
;
43}
44
45TEST_VM_F(LogStreamTest, from_log)class LogStreamTest_from_log_vm_Test : public LogStreamTest {
public: LogStreamTest_from_log_vm_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); LogStreamTest_from_log_vm_Test(LogStreamTest_from_log_vm_Test
const &) = delete; void operator=(LogStreamTest_from_log_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_from_log_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "from_log_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 45), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_from_log_vm_Test
>);void LogStreamTest_from_log_vm_Test::TestBody()
{
46 Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>
log;
47 LogStream stream(log.debug());
48
49 verify_stream(&stream);
50}
51
52TEST_VM_F(LogStreamTest, from_logtarget)class LogStreamTest_from_logtarget_vm_Test : public LogStreamTest
{ public: LogStreamTest_from_logtarget_vm_Test() {} private:
virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); LogStreamTest_from_logtarget_vm_Test
(LogStreamTest_from_logtarget_vm_Test const &) = delete; void
operator=(LogStreamTest_from_logtarget_vm_Test const &) =
delete;};::testing::TestInfo* const LogStreamTest_from_logtarget_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "from_logtarget_vm", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 52), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_from_logtarget_vm_Test
>);void LogStreamTest_from_logtarget_vm_Test::TestBody()
{
53 LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
, (LogTag::__NO_TAG)>
log;
54 LogStream stream(log);
55
56 verify_stream(&stream);
57}
58
59TEST_VM_F(LogStreamTest, handle)class LogStreamTest_handle_vm_Test : public LogStreamTest { public
: LogStreamTest_handle_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); LogStreamTest_handle_vm_Test(LogStreamTest_handle_vm_Test
const &) = delete; void operator=(LogStreamTest_handle_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_handle_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "handle_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 59), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_handle_vm_Test
>);void LogStreamTest_handle_vm_Test::TestBody()
{
60 LogStreamHandle(Debug, gc)LogStreamTemplate<LogLevel::Debug, (LogTag::_gc), (LogTag::
__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG)>
stream;
61
62 verify_stream(&stream);
63}
64
65TEST_VM_F(LogStreamTest, no_rm)class LogStreamTest_no_rm_vm_Test : public LogStreamTest { public
: LogStreamTest_no_rm_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); LogStreamTest_no_rm_vm_Test(LogStreamTest_no_rm_vm_Test
const &) = delete; void operator=(LogStreamTest_no_rm_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_no_rm_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "no_rm_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 65), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_no_rm_vm_Test
>);void LogStreamTest_no_rm_vm_Test::TestBody()
{
66 ResourceMark rm;
67 LogStream ls(Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>
::debug());
68 verify_stream(&ls);
69}
70
71TEST_VM_F(LogStreamTest, TestLineBufferAllocation)class LogStreamTest_TestLineBufferAllocation_vm_Test : public
LogStreamTest { public: LogStreamTest_TestLineBufferAllocation_vm_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); LogStreamTest_TestLineBufferAllocation_vm_Test
(LogStreamTest_TestLineBufferAllocation_vm_Test const &) =
delete; void operator=(LogStreamTest_TestLineBufferAllocation_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_TestLineBufferAllocation_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "TestLineBufferAllocation_vm", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 71), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_TestLineBufferAllocation_vm_Test
>);void LogStreamTest_TestLineBufferAllocation_vm_Test::TestBody
()
{
72 const int max_line_len = 1024;
73 char* const test_string = (char*) os::malloc(max_line_len, mtLogging);
74 memset(test_string, 'A', max_line_len);
75 Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>
log;
76 set_log_config(TestLogFileName, "gc=debug");
77 for (int interval = 1; interval < max_line_len; interval++) {
78 LogStream ls(log.debug());
79 int written = 0;
80 while (written < max_line_len) {
81 const int to_write = MIN2(interval, max_line_len - written);
Value stored to 'to_write' during its initialization is never read
82 ls.write(test_string, interval);
83 written += interval;
84 const char* const line_buffer = ls._current_line.buffer();
85 for (int i = 0; i < written; i++) {
86 ASSERT_TRUE(line_buffer[i] == 'A')switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(line_buffer[i] == 'A'
)) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 86, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "line_buffer[i] == 'A'", "false", "true").c_str()) = ::testing
::Message()
;
87 }
88 ASSERT_TRUE(line_buffer[written] == '\0')switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(line_buffer[written] ==
'\0')) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 88, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "line_buffer[written] == '\\0'", "false", "true").c_str()) =
::testing::Message()
;
89 }
90 }
91}
92
93// Test, in release build, that the internal line buffer of a LogStream
94// object caps out at 1M.
95TEST_VM_F(LogStreamTest, TestLineBufferAllocationCap)class LogStreamTest_TestLineBufferAllocationCap_vm_Test : public
LogStreamTest { public: LogStreamTest_TestLineBufferAllocationCap_vm_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); LogStreamTest_TestLineBufferAllocationCap_vm_Test
(LogStreamTest_TestLineBufferAllocationCap_vm_Test const &
) = delete; void operator=(LogStreamTest_TestLineBufferAllocationCap_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_TestLineBufferAllocationCap_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "TestLineBufferAllocationCap_vm", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 95), (::testing::internal::GetTypeId<LogStreamTest>()
), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_TestLineBufferAllocationCap_vm_Test
>);void LogStreamTest_TestLineBufferAllocationCap_vm_Test::
TestBody()
{
96 LogStream ls(Log(logging)LogImpl<(LogTag::_logging), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>
::info());
97 for (size_t i = 0; i < (1*M + 512); i ++) {
98 ls.print_raw("A");
99 }
100 const char* const line_buffer = ls._current_line.buffer();
101 ASSERT_TRUE(strlen(line_buffer) == 1*M - 1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(strlen(line_buffer) ==
1*M - 1)) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "strlen(line_buffer) == 1*M - 1", "false", "true").c_str())
= ::testing::Message()
;
102 // reset to prevent assert for unflushed content
103 ls._current_line.reset();
104}
105
106TEST_VM_F(LogStreamTest, autoflush_on_destruction)class LogStreamTest_autoflush_on_destruction_vm_Test : public
LogStreamTest { public: LogStreamTest_autoflush_on_destruction_vm_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); LogStreamTest_autoflush_on_destruction_vm_Test
(LogStreamTest_autoflush_on_destruction_vm_Test const &) =
delete; void operator=(LogStreamTest_autoflush_on_destruction_vm_Test
const &) = delete;};::testing::TestInfo* const LogStreamTest_autoflush_on_destruction_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"LogStreamTest", "autoflush_on_destruction_vm", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 106), (::testing::internal::GetTypeId<LogStreamTest>(
)), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< LogStreamTest_autoflush_on_destruction_vm_Test
>);void LogStreamTest_autoflush_on_destruction_vm_Test::TestBody
()
{
107 Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>
log;
108 set_log_config(TestLogFileName, "gc=debug");
109 {
110 LogStream stream(log.debug());
111 stream.print("ABCD"); // Unfinished line. I expect not to assert upon leaving the scope.
112 }
113 EXPECT_TRUE(file_contains_substring(TestLogFileName, "ABCD\n"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(file_contains_substring
(TestLogFileName, "ABCD\n"))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp"
, 113, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "file_contains_substring(TestLogFileName, \"ABCD\\n\")", "false"
, "true").c_str()) = ::testing::Message()
;
114}
115