From 93ea424cd1df77cb699b37173c0f939faa21cdba Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 26 Nov 2024 12:55:24 -0600 Subject: [PATCH] reverted remaining Valueflow changes (#7040) Move `valueFlowNumber` and `valueFlowEnumValue` back to valueflow.cpp and remove the unused header files. --- Makefile | 10 +----- lib/cppcheck.vcxproj | 4 --- lib/valueflow.cpp | 59 +++++++++++++++++++++++++++++++--- lib/vf_analyze.h | 25 -------------- lib/vf_array.h | 30 ----------------- lib/vf_arraybool.h | 30 ----------------- lib/vf_arrayelement.h | 30 ----------------- lib/vf_bitand.h | 30 ----------------- lib/vf_debug.h | 31 ------------------ lib/vf_enumvalue.cpp | 58 --------------------------------- lib/vf_enumvalue.h | 30 ----------------- lib/vf_functionreturn.h | 31 ------------------ lib/vf_globalconstvar.h | 30 ----------------- lib/vf_globalstaticvar.h | 30 ----------------- lib/vf_impossiblevalues.h | 30 ----------------- lib/vf_number.cpp | 58 --------------------------------- lib/vf_number.h | 30 ----------------- lib/vf_pointeralias.h | 30 ----------------- lib/vf_rightshift.h | 30 ----------------- lib/vf_sameexpressions.h | 30 ----------------- lib/vf_string.h | 30 ----------------- lib/vf_symbolicinfer.h | 30 ----------------- lib/vf_unknownfunctionreturn.h | 30 ----------------- oss-fuzz/Makefile | 10 +----- 24 files changed, 57 insertions(+), 679 deletions(-) delete mode 100644 lib/vf_analyze.h delete mode 100644 lib/vf_array.h delete mode 100644 lib/vf_arraybool.h delete mode 100644 lib/vf_arrayelement.h delete mode 100644 lib/vf_bitand.h delete mode 100644 lib/vf_debug.h delete mode 100644 lib/vf_enumvalue.cpp delete mode 100644 lib/vf_enumvalue.h delete mode 100644 lib/vf_functionreturn.h delete mode 100644 lib/vf_globalconstvar.h delete mode 100644 lib/vf_globalstaticvar.h delete mode 100644 lib/vf_impossiblevalues.h delete mode 100644 lib/vf_number.cpp delete mode 100644 lib/vf_number.h delete mode 100644 lib/vf_pointeralias.h delete mode 100644 lib/vf_rightshift.h delete mode 100644 lib/vf_sameexpressions.h delete mode 100644 lib/vf_string.h delete mode 100644 lib/vf_symbolicinfer.h delete mode 100644 lib/vf_unknownfunctionreturn.h diff --git a/Makefile b/Makefile index 77ffc1ca6b2..81974cbceb6 100644 --- a/Makefile +++ b/Makefile @@ -256,8 +256,6 @@ LIBOBJ = $(libcppdir)/valueflow.o \ $(libcppdir)/utils.o \ $(libcppdir)/vf_analyzers.o \ $(libcppdir)/vf_common.o \ - $(libcppdir)/vf_enumvalue.o \ - $(libcppdir)/vf_number.o \ $(libcppdir)/vf_settokenvalue.o \ $(libcppdir)/vfvalue.o @@ -459,7 +457,7 @@ validateRules: ###### Build -$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyze.h lib/vf_analyzers.h lib/vf_common.h lib/vf_enumvalue.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h +$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyzers.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp $(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h @@ -657,12 +655,6 @@ $(libcppdir)/vf_analyzers.o: lib/vf_analyzers.cpp lib/addoninfo.h lib/analyzer.h $(libcppdir)/vf_common.o: lib/vf_common.cpp lib/addoninfo.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp -$(libcppdir)/vf_enumvalue.o: lib/vf_enumvalue.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_enumvalue.h lib/vfvalue.h - $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp - -$(libcppdir)/vf_number.o: lib/vf_number.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h - $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_number.cpp - $(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/astutils.h lib/calculate.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_settokenvalue.cpp diff --git a/lib/cppcheck.vcxproj b/lib/cppcheck.vcxproj index 502351e6924..ad00b1d8c0b 100644 --- a/lib/cppcheck.vcxproj +++ b/lib/cppcheck.vcxproj @@ -91,8 +91,6 @@ - - @@ -179,8 +177,6 @@ - - diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 775193b34ba..c4ea3f7a277 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -105,7 +105,6 @@ #include "valueptr.h" #include "vfvalue.h" -#include "vf_analyze.h" #include "vf_analyzers.h" #include "vf_common.h" #include "vf_settokenvalue.h" @@ -555,6 +554,31 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, int m return 0; } +static void valueFlowNumber(TokenList &tokenlist, const Settings& settings) +{ + for (Token *tok = tokenlist.front(); tok;) { + tok = ValueFlow::valueFlowSetConstantValue(tok, settings); + } + + if (tokenlist.isCPP() || settings.standards.c >= Standards::C23) { + for (Token *tok = tokenlist.front(); tok; tok = tok->next()) { + if (tok->isName() && !tok->varId() && Token::Match(tok, "false|true")) { + ValueFlow::Value value(tok->str() == "true"); + if (!tok->isTemplateArg()) + value.setKnown(); + setTokenValue(tok, std::move(value), settings); + } else if (Token::Match(tok, "[(,] NULL [,)]")) { + // NULL function parameters are not simplified in the + // normal tokenlist + ValueFlow::Value value(0); + if (!tok->isTemplateArg()) + value.setKnown(); + setTokenValue(tok->next(), std::move(value), settings); + } + } + } +} + static void valueFlowString(TokenList& tokenlist, const Settings& settings) { for (Token* tok = tokenlist.front(); tok; tok = tok->next()) { @@ -1113,6 +1137,33 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett } } +static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings & settings) +{ + for (Scope & scope : symboldatabase.scopeList) { + if (scope.type != Scope::eEnum) + continue; + MathLib::bigint value = 0; + bool prev_enum_is_known = true; + + for (Enumerator & enumerator : scope.enumeratorList) { + if (enumerator.start) { + auto* rhs = const_cast(enumerator.start->previous()->astOperand2()); + ValueFlow::valueFlowConstantFoldAST(rhs, settings); + if (rhs && rhs->hasKnownIntValue()) { + enumerator.value = rhs->values().front().intvalue; + enumerator.value_known = true; + value = enumerator.value + 1; + prev_enum_is_known = true; + } else + prev_enum_is_known = false; + } else if (prev_enum_is_known) { + enumerator.value = value++; + enumerator.value_known = true; + } + } + } +} + static void valueFlowGlobalConstVar(TokenList& tokenList, const Settings& settings) { // Get variable values... @@ -7164,13 +7215,13 @@ void ValueFlow::setValues(TokenList& tokenlist, ValueFlowPassRunner runner{ValueFlowState{tokenlist, symboldatabase, errorLogger, settings}, timerResults}; runner.run_once({ - VFA(analyzeEnumValue(symboldatabase, settings)), - VFA(analyzeNumber(tokenlist, settings)), + VFA(valueFlowEnumValue(symboldatabase, settings)), + VFA(valueFlowNumber(tokenlist, settings)), VFA(valueFlowString(tokenlist, settings)), VFA(valueFlowArray(tokenlist, settings)), VFA(valueFlowUnknownFunctionReturn(tokenlist, settings)), VFA(valueFlowGlobalConstVar(tokenlist, settings)), - VFA(analyzeEnumValue(symboldatabase, settings)), + VFA(valueFlowEnumValue(symboldatabase, settings)), VFA(valueFlowGlobalStaticVar(tokenlist, settings)), VFA(valueFlowPointerAlias(tokenlist, settings)), VFA(valueFlowLifetime(tokenlist, errorLogger, settings)), diff --git a/lib/vf_analyze.h b/lib/vf_analyze.h deleted file mode 100644 index eb0ec1154d1..00000000000 --- a/lib/vf_analyze.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfAnalyzeH -#define vfAnalyzeH - -#include "vf_enumvalue.h" // IWYU pragma: export -#include "vf_number.h" // IWYU pragma: export - -#endif // vfAnalyzeH diff --git a/lib/vf_array.h b/lib/vf_array.h deleted file mode 100644 index fbcd7489a76..00000000000 --- a/lib/vf_array.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfArrayH -#define vfArrayH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeArray(TokenList &tokenlist, const Settings &settings); -} - -#endif // vfArrayH diff --git a/lib/vf_arraybool.h b/lib/vf_arraybool.h deleted file mode 100644 index 8a616da1566..00000000000 --- a/lib/vf_arraybool.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfArrayBoolH -#define vfArrayBoolH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeArrayBool(TokenList &tokenlist, const Settings &settings); -} - -#endif // vfArrayBoolH diff --git a/lib/vf_arrayelement.h b/lib/vf_arrayelement.h deleted file mode 100644 index 6930ea25ab9..00000000000 --- a/lib/vf_arrayelement.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfArrayElementH -#define vfArrayElementH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeArrayElement(TokenList& tokenlist, const Settings& settings); -} - -#endif // vfArrayElementH diff --git a/lib/vf_bitand.h b/lib/vf_bitand.h deleted file mode 100644 index 616cf2ee0e9..00000000000 --- a/lib/vf_bitand.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfBitAndH -#define vfBitAndH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeBitAnd(TokenList &tokenlist, const Settings& settings); -} - -#endif // vfBitAndH diff --git a/lib/vf_debug.h b/lib/vf_debug.h deleted file mode 100644 index c8d367bed93..00000000000 --- a/lib/vf_debug.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfDebugH -#define vfDebugH - -class TokenList; -class ErrorLogger; -class Settings; - -namespace ValueFlow -{ - void analyzeDebug(TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings); -} - -#endif // vfDebugH diff --git a/lib/vf_enumvalue.cpp b/lib/vf_enumvalue.cpp deleted file mode 100644 index 634169aff06..00000000000 --- a/lib/vf_enumvalue.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -#include "vf_enumvalue.h" - -#include "mathlib.h" -#include "symboldatabase.h" -#include "token.h" -#include "valueflow.h" -#include "vfvalue.h" - -#include -#include - -namespace ValueFlow -{ - void analyzeEnumValue(SymbolDatabase & symboldatabase, const Settings & settings) - { - for (Scope & scope : symboldatabase.scopeList) { - if (scope.type != Scope::eEnum) - continue; - MathLib::bigint value = 0; - bool prev_enum_is_known = true; - - for (Enumerator & enumerator : scope.enumeratorList) { - if (enumerator.start) { - auto* rhs = const_cast(enumerator.start->previous()->astOperand2()); - valueFlowConstantFoldAST(rhs, settings); - if (rhs && rhs->hasKnownIntValue()) { - enumerator.value = rhs->values().front().intvalue; - enumerator.value_known = true; - value = enumerator.value + 1; - prev_enum_is_known = true; - } else - prev_enum_is_known = false; - } else if (prev_enum_is_known) { - enumerator.value = value++; - enumerator.value_known = true; - } - } - } - } -} diff --git a/lib/vf_enumvalue.h b/lib/vf_enumvalue.h deleted file mode 100644 index efac5d60232..00000000000 --- a/lib/vf_enumvalue.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfEnumValueH -#define vfEnumValueH - -class SymbolDatabase; -class Settings; - -namespace ValueFlow -{ - void analyzeEnumValue(SymbolDatabase & symboldatabase, const Settings & settings); -} - -#endif // vfEnumValueH diff --git a/lib/vf_functionreturn.h b/lib/vf_functionreturn.h deleted file mode 100644 index 25baba34184..00000000000 --- a/lib/vf_functionreturn.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfFunctionReturnH -#define vfFunctionReturnH - -class TokenList; -class ErrorLogger; -class Settings; - -namespace ValueFlow -{ - void analyzeFunctionReturn(TokenList &tokenlist, ErrorLogger &errorLogger, const Settings& settings); -} - -#endif // vfFunctionReturnH diff --git a/lib/vf_globalconstvar.h b/lib/vf_globalconstvar.h deleted file mode 100644 index 2fd525ed52b..00000000000 --- a/lib/vf_globalconstvar.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfGlobalConstVarH -#define vfGlobalConstVarH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeGlobalConstVar(TokenList& tokenList, const Settings &settings); -} - -#endif // vfGlobalConstVarH diff --git a/lib/vf_globalstaticvar.h b/lib/vf_globalstaticvar.h deleted file mode 100644 index dcbae981eb9..00000000000 --- a/lib/vf_globalstaticvar.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfGlobalStaticVarH -#define vfGlobalStaticVarH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeGlobalStaticVar(TokenList &tokenList, const Settings &settings); -} - -#endif // vfGlobalStaticVarH diff --git a/lib/vf_impossiblevalues.h b/lib/vf_impossiblevalues.h deleted file mode 100644 index 21a341ea8d1..00000000000 --- a/lib/vf_impossiblevalues.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfImpossibleValuesH -#define vfImpossibleValuesH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeImpossibleValues(TokenList& tokenList, const Settings& settings); -} - -#endif // vfImpossibleValuesH diff --git a/lib/vf_number.cpp b/lib/vf_number.cpp deleted file mode 100644 index 980c4e7fe43..00000000000 --- a/lib/vf_number.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -#include "vf_number.h" - -#include "settings.h" -#include "token.h" -#include "tokenlist.h" -#include "vfvalue.h" - -#include "vf_common.h" -#include "vf_settokenvalue.h" - -#include -#include - -namespace ValueFlow -{ - void analyzeNumber(TokenList &tokenlist, const Settings& settings) - { - for (Token *tok = tokenlist.front(); tok;) { - tok = valueFlowSetConstantValue(tok, settings); - } - - if (tokenlist.isCPP() || settings.standards.c >= Standards::C23) { - for (Token *tok = tokenlist.front(); tok; tok = tok->next()) { - if (tok->isName() && !tok->varId() && Token::Match(tok, "false|true")) { - ValueFlow::Value value(tok->str() == "true"); - if (!tok->isTemplateArg()) - value.setKnown(); - setTokenValue(tok, std::move(value), settings); - } else if (Token::Match(tok, "[(,] NULL [,)]")) { - // NULL function parameters are not simplified in the - // normal tokenlist - ValueFlow::Value value(0); - if (!tok->isTemplateArg()) - value.setKnown(); - setTokenValue(tok->next(), std::move(value), settings); - } - } - } - } -} diff --git a/lib/vf_number.h b/lib/vf_number.h deleted file mode 100644 index 6cb46312433..00000000000 --- a/lib/vf_number.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfNumberH -#define vfNumberH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeNumber(TokenList &tokenlist, const Settings& settings); -} - -#endif // vfNumberH diff --git a/lib/vf_pointeralias.h b/lib/vf_pointeralias.h deleted file mode 100644 index 520705586eb..00000000000 --- a/lib/vf_pointeralias.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfPointerAliasH -#define vfPointerAliasH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzePointerAlias(TokenList &tokenlist, const Settings& settings); -} - -#endif // vfPointerAliasH diff --git a/lib/vf_rightshift.h b/lib/vf_rightshift.h deleted file mode 100644 index e7e16028281..00000000000 --- a/lib/vf_rightshift.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfRightShiftH -#define vfRightShiftH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeRightShift(TokenList &tokenList, const Settings& settings); -} - -#endif // vfRightShiftH diff --git a/lib/vf_sameexpressions.h b/lib/vf_sameexpressions.h deleted file mode 100644 index 97a579dac21..00000000000 --- a/lib/vf_sameexpressions.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfSameExpressionsH -#define vfSameExpressionsH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeSameExpressions(TokenList &tokenlist, const Settings& settings); -} - -#endif // vfSameExpressionsH diff --git a/lib/vf_string.h b/lib/vf_string.h deleted file mode 100644 index 7d4af17447d..00000000000 --- a/lib/vf_string.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfStringH -#define vfStringH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeString(TokenList &tokenlist, const Settings& settings); -} - -#endif // vfStringH diff --git a/lib/vf_symbolicinfer.h b/lib/vf_symbolicinfer.h deleted file mode 100644 index 7ec5374cd39..00000000000 --- a/lib/vf_symbolicinfer.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfSymbolicInferH -#define vfSymbolicInferH - -class SymbolDatabase; -class Settings; - -namespace ValueFlow -{ - void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const Settings& settings); -} - -#endif // vfSymbolicInferH diff --git a/lib/vf_unknownfunctionreturn.h b/lib/vf_unknownfunctionreturn.h deleted file mode 100644 index 2e93970b57f..00000000000 --- a/lib/vf_unknownfunctionreturn.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- - * 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 . - */ - -#ifndef vfUnknownFunctionReturnH -#define vfUnknownFunctionReturnH - -class TokenList; -class Settings; - -namespace ValueFlow -{ - void analyzeUnknownFunctionReturn(TokenList &tokenlist, const Settings &settings); -} - -#endif // vfUnknownFunctionReturnH diff --git a/oss-fuzz/Makefile b/oss-fuzz/Makefile index 353c33b569f..71350dd0005 100644 --- a/oss-fuzz/Makefile +++ b/oss-fuzz/Makefile @@ -99,8 +99,6 @@ LIBOBJ = $(libcppdir)/valueflow.o \ $(libcppdir)/utils.o \ $(libcppdir)/vf_analyzers.o \ $(libcppdir)/vf_common.o \ - $(libcppdir)/vf_enumvalue.o \ - $(libcppdir)/vf_number.o \ $(libcppdir)/vf_settokenvalue.o \ $(libcppdir)/vfvalue.o @@ -146,7 +144,7 @@ simplecpp.o: ../externals/simplecpp/simplecpp.cpp ../externals/simplecpp/simplec tinyxml2.o: ../externals/tinyxml2/tinyxml2.cpp ../externals/tinyxml2/tinyxml2.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ ../externals/tinyxml2/tinyxml2.cpp -$(libcppdir)/valueflow.o: ../lib/valueflow.cpp ../lib/addoninfo.h ../lib/analyzer.h ../lib/astutils.h ../lib/calculate.h ../lib/check.h ../lib/checkuninitvar.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/findtoken.h ../lib/forwardanalyzer.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/programmemory.h ../lib/reverseanalyzer.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/timer.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/valueptr.h ../lib/vf_analyze.h ../lib/vf_analyzers.h ../lib/vf_common.h ../lib/vf_enumvalue.h ../lib/vf_number.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h +$(libcppdir)/valueflow.o: ../lib/valueflow.cpp ../lib/addoninfo.h ../lib/analyzer.h ../lib/astutils.h ../lib/calculate.h ../lib/check.h ../lib/checkuninitvar.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/findtoken.h ../lib/forwardanalyzer.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/programmemory.h ../lib/reverseanalyzer.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/timer.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/valueptr.h ../lib/vf_analyzers.h ../lib/vf_common.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp $(libcppdir)/tokenize.o: ../lib/tokenize.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/preprocessor.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/summaries.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/timer.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/vfvalue.h @@ -344,12 +342,6 @@ $(libcppdir)/vf_analyzers.o: ../lib/vf_analyzers.cpp ../lib/addoninfo.h ../lib/a $(libcppdir)/vf_common.o: ../lib/vf_common.cpp ../lib/addoninfo.h ../lib/astutils.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/utils.h ../lib/valueflow.h ../lib/vf_common.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp -$(libcppdir)/vf_enumvalue.o: ../lib/vf_enumvalue.cpp ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/utils.h ../lib/valueflow.h ../lib/vf_enumvalue.h ../lib/vfvalue.h - $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp - -$(libcppdir)/vf_number.o: ../lib/vf_number.cpp ../lib/addoninfo.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vf_common.h ../lib/vf_number.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h - $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_number.cpp - $(libcppdir)/vf_settokenvalue.o: ../lib/vf_settokenvalue.cpp ../lib/addoninfo.h ../lib/astutils.h ../lib/calculate.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/utils.h ../lib/valueflow.h ../lib/vf_common.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_settokenvalue.cpp