Skip to content

Commit

Permalink
Fix instrumentation of subprograms with only return statement
Browse files Browse the repository at this point in the history
Previously assumed that a given line would have at most one
instrumentation point before and at most one after, but in the case of a
subprogram with only a single return statement, then that one line has
three instrumentation points. Fixed by handling arbitrarily many before
and after instrumentation points per line.
  • Loading branch information
nchaimov committed Dec 20, 2024
1 parent 2dc7159 commit aed21ae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/salt_instrument_flang_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
llvm::errs() << "ERROR: execution part had no end source location!\n";
}

const auto startLoc{startLocOpt.value()};
const auto endLoc{endLocOpt.value()};
const auto& startLoc{startLocOpt.value()};
const auto& endLoc{endLocOpt.value()};

// Insert the timer start in the Pre phase (when we first visit the node)
// and the timer stop in the Post phase (when we return after visiting the node's children).
Expand Down Expand Up @@ -705,12 +705,12 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
auto instIter{instPts.cbegin()};
while (std::getline(inputStream, line)) {
++lineNum;
if (instIter != instPts.cend() && instIter->startLine == lineNum && instIter->instrumentBefore()) {
while (instIter != instPts.cend() && instIter->startLine == lineNum && instIter->instrumentBefore()) {
outputStream << getInstrumentationPointString(*instIter, instMap) << "\n";
++instIter;
}
outputStream << line << "\n";
if (instIter != instPts.cend() && instIter->startLine == lineNum && !instIter->instrumentBefore()) {
while (instIter != instPts.cend() && instIter->startLine == lineNum && !instIter->instrumentBefore()) {
outputStream << getInstrumentationPointString(*instIter, instMap) << "\n";
++instIter;
}
Expand Down

0 comments on commit aed21ae

Please sign in to comment.