From 10f48a1aeeca856e25307a0d1da307c9e27a4a5e Mon Sep 17 00:00:00 2001 From: vl241552 <vincent.lorrain@cea.fr> Date: Mon, 9 Oct 2023 08:45:26 +0000 Subject: [PATCH] [NodeRegex][fix] --- CMakeLists.txt | 16 +++++++++---- include/aidge/hook/hook.hpp | 2 +- include/aidge/nodeTester/ConditionalData.hpp | 2 +- include/aidge/operator/GenericOperator.hpp | 1 + src/graphRegex/GraphFsmInterpreter.cpp | 4 ++-- src/nodeTester/ConditionalInterpreter.cpp | 25 ++++++++++++++++++++ unit_tests/graphMatching/Test_GRegex.cpp | 12 ++++++++++ unit_tests/graphMatching/Test_SeqStm.cpp | 8 +++++++ unit_tests/graphMatching/Test_StmFactory.cpp | 15 ++++++++++++ unit_tests/graphRegex/Test_FsmMatch.cpp | 2 -- 10 files changed, 77 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b764086c8..45ad49ba7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,12 +66,20 @@ endif() target_compile_features(${module_name} PRIVATE cxx_std_14) +if (DOSANITIZE STREQUAL "ON") +set(SANITIZE_FLAGS -fsanitize=address,leak,undefined,float-divide-by-zero -fno-omit-frame-pointer) +else() +set(SANITIZE_FLAGS) +endif() + target_compile_options(${module_name} PRIVATE - $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: - -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow $<$<BOOL:${WERROR}>:-Werror>>) +$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: +-Wall -Wextra -fPIC -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow -fstrict-aliasing -Wstrict-aliasing=1 $<$<BOOL:${WERROR}>:-Werror> ${SANITIZE_FLAGS}>) target_compile_options(${module_name} PRIVATE - $<$<CXX_COMPILER_ID:MSVC>: - /W4>) +$<$<CXX_COMPILER_ID:MSVC>: +/W4>) + +target_link_options(${module_name} PUBLIC ${SANITIZE_FLAGS}) if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) append_coverage_compiler_flags() diff --git a/include/aidge/hook/hook.hpp b/include/aidge/hook/hook.hpp index 0448659b9..f263ac0e4 100644 --- a/include/aidge/hook/hook.hpp +++ b/include/aidge/hook/hook.hpp @@ -31,7 +31,7 @@ protected: public: Hook(std::shared_ptr<Operator> op) : mOperator(op) {} - virtual ~Hook(); + virtual ~Hook() = default; virtual void call() = 0; diff --git a/include/aidge/nodeTester/ConditionalData.hpp b/include/aidge/nodeTester/ConditionalData.hpp index 9d889d6a0..d8ed187f0 100644 --- a/include/aidge/nodeTester/ConditionalData.hpp +++ b/include/aidge/nodeTester/ConditionalData.hpp @@ -34,7 +34,7 @@ struct ConditionalData { */ //void* value; std::unique_ptr<BaseConditionalValue> value; - const std::type_info* type; + const std::type_info* type =nullptr; ///////////////////////////////// // diff --git a/include/aidge/operator/GenericOperator.hpp b/include/aidge/operator/GenericOperator.hpp index 184100174..8b95a219d 100644 --- a/include/aidge/operator/GenericOperator.hpp +++ b/include/aidge/operator/GenericOperator.hpp @@ -24,6 +24,7 @@ #include "aidge/utils/Registrar.hpp" #include "aidge/utils/Types.h" + namespace Aidge { class GenericOperator_Op : public Operator, diff --git a/src/graphRegex/GraphFsmInterpreter.cpp b/src/graphRegex/GraphFsmInterpreter.cpp index 6d04fc97c..2984ab4fb 100644 --- a/src/graphRegex/GraphFsmInterpreter.cpp +++ b/src/graphRegex/GraphFsmInterpreter.cpp @@ -63,7 +63,6 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::keyF(std::shared_ptr<AstNode<gReg return graph; } - std::shared_ptr<FsmGraph> GraphFsmInterpreter::sepF(std::shared_ptr<FsmGraph> leftFsm,std::shared_ptr<FsmGraph> rigthFsm){ size_t idxLeft = leftFsm->getNbSubFsm(); @@ -73,7 +72,6 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::sepF(std::shared_ptr<FsmGraph> le return leftFsm; } - std::shared_ptr<FsmGraph> GraphFsmInterpreter::nextF(std::shared_ptr<FsmGraph> leftFsm,std::shared_ptr<FsmGraph> rigthFsm){ /* combine the 2 Graph @@ -89,6 +87,7 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::nextF(std::shared_ptr<FsmGraph> l //the rigthFsm is no longer usfull return leftFsm; } + std::shared_ptr<FsmGraph> GraphFsmInterpreter::qomF(std::shared_ptr<FsmGraph> fsm){ /* + @@ -154,6 +153,7 @@ std::shared_ptr<FsmGraph> GraphFsmInterpreter::qomF(std::shared_ptr<FsmGraph> fs return fsm; } + std::shared_ptr<FsmGraph> GraphFsmInterpreter::qzmF(std::shared_ptr<FsmGraph> fsm){ /* qomf and a bypass empty start to valide diff --git a/src/nodeTester/ConditionalInterpreter.cpp b/src/nodeTester/ConditionalInterpreter.cpp index ccf9794a8..48947035e 100644 --- a/src/nodeTester/ConditionalInterpreter.cpp +++ b/src/nodeTester/ConditionalInterpreter.cpp @@ -223,6 +223,11 @@ using namespace Aidge; throw std::runtime_error(errorMessage.str()); } dataVector.push_back(data); + + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } @@ -255,6 +260,10 @@ using namespace Aidge; throw std::runtime_error("EQ Unknown type encountered :" + a->getType() ); } dataVector.push_back(data); + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } @@ -286,6 +295,10 @@ using namespace Aidge; throw std::runtime_error("NEQ Unknown type encountered :" + a->getType() ); } dataVector.push_back(data); + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } @@ -309,6 +322,10 @@ using namespace Aidge; dataVector.push_back(data); + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } @@ -332,6 +349,10 @@ using namespace Aidge; dataVector.push_back(data); + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } @@ -354,6 +375,10 @@ using namespace Aidge; dataVector.push_back(data); + //clear + for (std::size_t i = 0; i < datas.size(); ++i) { + delete datas[i]; + } datas.clear(); return dataVector; } diff --git a/unit_tests/graphMatching/Test_GRegex.cpp b/unit_tests/graphMatching/Test_GRegex.cpp index 7184fad76..2c5907d82 100644 --- a/unit_tests/graphMatching/Test_GRegex.cpp +++ b/unit_tests/graphMatching/Test_GRegex.cpp @@ -53,6 +53,10 @@ TEST_CASE("Create good init GRegex", "[GRegex]") { // Perform tests REQUIRE(GReg.getStmInit().size() == 1); REQUIRE(GReg.getStmFab().getNumberOfStm() == 1); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } @@ -101,6 +105,10 @@ TEST_CASE("Function matchFromStartNodes | One Match of Nodes sequence", "[GRegex // Perform tests REQUIRE(result == true_result); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } TEST_CASE("Function matchFromStartNodes | One Match of parallel branches ", "[GRegex]") { @@ -166,6 +174,10 @@ TEST_CASE("Function matchFromStartNodes | One Match of parallel branches ", "[GR // Perform tests REQUIRE(result == true_result); REQUIRE(wrong_start_result == empty_result); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } /* diff --git a/unit_tests/graphMatching/Test_SeqStm.cpp b/unit_tests/graphMatching/Test_SeqStm.cpp index baabbbc3c..db8662e33 100644 --- a/unit_tests/graphMatching/Test_SeqStm.cpp +++ b/unit_tests/graphMatching/Test_SeqStm.cpp @@ -79,6 +79,10 @@ TEST_CASE("Create good init SeqStm", "[SeqStm]") { REQUIRE(stm.getAllCommonNode().size() == 0); REQUIRE(stm.getAllNodeTested().size() == 0); REQUIRE(stm.getAllNodeValidated().size() == 0); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } TEST_CASE("Test testNode function", "[SeqStm]") { @@ -156,4 +160,8 @@ TEST_CASE("Test testNode function", "[SeqStm]") { REQUIRE(stm.isStmBlocked() == true); REQUIRE(stm.getAllNodeTested() == testAllNodeTested); REQUIRE(stm.getAllNodeValidated() == testAllNodeValidated); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } \ No newline at end of file diff --git a/unit_tests/graphMatching/Test_StmFactory.cpp b/unit_tests/graphMatching/Test_StmFactory.cpp index b595372fd..3c66d0fa8 100644 --- a/unit_tests/graphMatching/Test_StmFactory.cpp +++ b/unit_tests/graphMatching/Test_StmFactory.cpp @@ -36,6 +36,10 @@ TEST_CASE("Create good init StmFactory", "[StmFactory]") { } StmFactory stmF(nodesRegex); REQUIRE(stmF.getNumberOfStm() == 0); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } TEST_CASE("Test in makeNewStm the getStmIdx StmFactory", "[SeqStm]") { @@ -66,6 +70,10 @@ TEST_CASE("Test in makeNewStm the getStmIdx StmFactory", "[SeqStm]") { //test the number of stm REQUIRE(stmF.getNumberOfStm() == 2); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } TEST_CASE("Test in makeNewStm the stm StmFactory", "[SeqStm]") { @@ -123,6 +131,9 @@ TEST_CASE("Test in makeNewStm the stm StmFactory", "[SeqStm]") { REQUIRE(stm->getAllNodeTested() == testAllNodeTested); REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated); + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } @@ -185,5 +196,9 @@ TEST_CASE("Test in duplicateStm StmFactory", "[SeqStm]") { REQUIRE(stmD->isStmBlocked() == false); REQUIRE(stmD->getAllNodeTested().size() == 0); REQUIRE(stmD->getAllNodeValidated().size() == 0); + + for (const std::string& key : nodeTypeKey) { + delete nodesRegex[key]; + } } diff --git a/unit_tests/graphRegex/Test_FsmMatch.cpp b/unit_tests/graphRegex/Test_FsmMatch.cpp index d89b274b3..cb66f4bfb 100644 --- a/unit_tests/graphRegex/Test_FsmMatch.cpp +++ b/unit_tests/graphRegex/Test_FsmMatch.cpp @@ -86,6 +86,4 @@ TEST_CASE("FsmMatch") { } - - } \ No newline at end of file -- GitLab