From 1e5ae1ef807a2895e604026bc61ab581afecf95c Mon Sep 17 00:00:00 2001 From: Grigorii Gusev Date: Mon, 8 Apr 2024 17:51:50 +0300 Subject: [PATCH 1/2] private_removing: fix bugreport_1712578151 --- .../Sapfor_2017/_src/Transformations/private_removing.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp index ed08c73..0a59ed6 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp @@ -1642,6 +1642,9 @@ static vector buildDefUsePairs(Context* ctx, const CFG_Type& CF for (auto& instruction : blockInstructionsVector) { SgStatement* stmt = instruction->getInstruction()->getOperator(); + if (stmt == useInsertedStmt.insertedStmt) + break; + if (stmt->variant() == ASSIGN_STAT && stmt->expr(0)->symbol()->identifier() == defVarName && !isVarChangedBetween(defVarName, stmt, useInsertedStmt.insertedStmt)) From 492df9fe6c5baadcad703820595ba8fa5ee91880 Mon Sep 17 00:00:00 2001 From: Grigorii Gusev Date: Tue, 9 Apr 2024 00:37:44 +0300 Subject: [PATCH 2/2] private_removing: add indirect usage check for func_call expressions --- .../_src/Transformations/private_removing.cpp | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp index 0a59ed6..2bb2b7a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/private_removing.cpp @@ -1205,9 +1205,10 @@ static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLi for (int i = 0; i < funcCallExp->numberOfArgs(); ++i) { SgExpression* funcArg = funcCallExp->arg(i); - if (funcInfo->funcParams.isArgOut(i) - && funcArg->symbol() != nullptr - && isEqSymbols(funcArg->symbol(), ctx->arraySymbol)) + if (funcArg->symbol() == nullptr || !isEqSymbols(funcArg->symbol(), ctx->arraySymbol)) + continue; + + if (funcInfo->funcParams.isArgOut(i) || funcArg->lhs() == nullptr) { auto fixedVec = getFixedSubscriptsVector((SgArrayRefExp*)funcArg, ctx->dimensionsNum); fixedSubscripts.push_back(fixedVec); @@ -1295,6 +1296,9 @@ static vector getCommonBlockGroupedVar(FuncInfo* curFunc, SgSymbol* v static void checkIndirectUsage(Context* ctx, FuncInfo* calledFunc, vector commonBlockGroupedVar, set& visitedFuncs, vector>& indirectUsageMasks) { + if (calledFunc == nullptr) + return; + if (visitedFuncs.find(calledFunc->funcName) != visitedFuncs.end()) return; @@ -1325,6 +1329,27 @@ static void checkIndirectUsage(Context* ctx, FuncInfo* calledFunc, vector commonBlockGroupedVar, + set& visitedFuncs, vector>& indirectUsageMasks) +{ + if (exp == nullptr) + return; + + if (exp->variant() == FUNC_CALL) + { + SgFunctionCallExp* funcCallExp = (SgFunctionCallExp*)exp; + string funcName = funcCallExp->funName()->identifier(); + FuncInfo* funcInfo = findFuncByName(funcName, ctx->allFuncInfo); + if (funcInfo != nullptr) + checkIndirectUsage(ctx, funcInfo, commonBlockGroupedVar, visitedFuncs, indirectUsageMasks); + } + + checkIndirectUsage(ctx, exp->lhs(), commonBlockGroupedVar, visitedFuncs, indirectUsageMasks); + checkIndirectUsage(ctx, exp->rhs(), commonBlockGroupedVar, visitedFuncs, indirectUsageMasks); +} + // checkIndirectUsage returns masks of array indirect usage in any function call in loop // (indirect usage is usage through common blocks) and writes messages about it static vector> checkIndirectUsage(Context* ctx) @@ -1348,6 +1373,9 @@ static vector> checkIndirectUsage(Context* ctx) FuncInfo* calledFunc = findFuncByName(procName, ctx->allFuncInfo); checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFunctions, indirectUsageMasks); } + + for (int i = 0; i < 3; ++i) + checkIndirectUsage(ctx, st->expr(i), commonBlockGroupedVar, visitedFunctions, indirectUsageMasks); } return indirectUsageMasks;