Skip to content

Commit

Permalink
fixed #13607 - print float values as such in valueflow debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 6, 2025
1 parent f19ddb1 commit 4e4997c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ TESTOBJ = test/fixture.o \
test/testutils.o \
test/testvaarg.o \
test/testvalueflow.o \
test/testvarid.o
test/testvarid.o \
test/testvfvalue.o

.PHONY: run-dmake tags

Expand Down Expand Up @@ -900,6 +901,9 @@ test/testvalueflow.o: test/testvalueflow.cpp externals/simplecpp/simplecpp.h lib
test/testvarid.o: test/testvarid.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvarid.cpp

test/testvfvalue.o: test/testvfvalue.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvfvalue.cpp

externals/simplecpp/simplecpp.o: externals/simplecpp/simplecpp.cpp externals/simplecpp/simplecpp.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ externals/simplecpp/simplecpp.cpp

Expand Down
3 changes: 2 additions & 1 deletion lib/vfvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "vfvalue.h"

#include "errortypes.h"
#include "mathlib.h"
#include "token.h"

#include <sstream>
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace ValueFlow {
ss << this->tokvalue->str();
break;
case ValueType::FLOAT:
ss << this->floatValue;
ss << MathLib::toString(this->floatValue);
break;
case ValueType::MOVED:
ss << toString(this->moveKind);
Expand Down
8 changes: 4 additions & 4 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3072,12 +3072,12 @@ def test_debug_valueflow(tmp_path):
'##Value flow',
'File {}'.format(str(test_file).replace('\\', '/')),
'Line 3',
' = always 2',
' 1.0 always 1',
' / always 2',
' = always 2.0',
' 1.0 always 1.0',
' / always 2.0',
' 0.5 always 0.5',
'Line 4',
' d always {symbolic=(1.0/0.5),2}'
' d always {symbolic=(1.0/0.5),2.0}'
]


Expand Down
1 change: 1 addition & 0 deletions test/testrunner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<ClCompile Include="testvaarg.cpp" />
<ClCompile Include="testvalueflow.cpp" />
<ClCompile Include="testvarid.cpp" />
<ClCompile Include="testvfvalue.cpp" />
</ItemGroup>
<ItemGroup Label="HeaderFiles">
<ClInclude Include="..\cli\cmdlineparser.h" />
Expand Down
48 changes: 48 additions & 0 deletions test/testvfvalue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2024 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "fixture.h"
#include "vfvalue.h"

class TestValueFlowValue : public TestFixture {
public:
TestValueFlowValue() : TestFixture("TestValueFlowValue") {}

private:
void run() override {
TEST_CASE(toString);
}

void toString() const {
{
ValueFlow::Value v;
ASSERT_EQUALS("0", v.toString());
v.intvalue = -1;
ASSERT_EQUALS("-1", v.toString());
}
{
ValueFlow::Value v;
v.valueType = ValueFlow::Value::ValueType::FLOAT;
ASSERT_EQUALS("0.0", v.toString());
v.floatValue = 0.0000000000001;
ASSERT_EQUALS("1e-13", v.toString());
}
}
};

REGISTER_TEST(TestValueFlowValue)

0 comments on commit 4e4997c

Please sign in to comment.