Skip to content

Commit

Permalink
Sanity check order of instrumentation points, handle missing end case
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaimov committed Dec 17, 2024
1 parent fa43fe9 commit 37fee15
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/salt_instrument_flang_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
}

bool operator<(const SaltInstrumentationPoint &other) const {
if (startLine == other.startLine) {
return instrumentBefore();
}
return startLine < other.startLine;
}

Expand Down Expand Up @@ -210,9 +213,6 @@ class SaltInstrumentAction final : public PluginParseTreeAction {

// TODO split location-getting routines into a separate file

// TODO The source position functions can fail if no source position exists
// Need to handle that case better.

[[nodiscard]] std::optional<Fortran::parser::SourcePosition> getLocation(
const Fortran::parser::OpenMPDeclarativeConstruct &construct,
const bool end) {
Expand Down Expand Up @@ -282,7 +282,14 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
},
[&](const Fortran::parser::OpenACCLoopConstruct &c) -> std::optional<
Fortran::parser::SourcePosition> {
// TODO handle end case (complicated because end statement and do construct are optional)
if (end) {
if (const auto &maybeDo = std::get<std::optional<Fortran::parser::DoConstruct> >(c.t);
maybeDo.has_value()) {
return locationFromSource(
std::get<Fortran::parser::Statement<Fortran::parser::EndDoStmt> >(maybeDo.value().t).
source, end);
}
}
return locationFromSource(std::get<Fortran::parser::AccBeginLoopDirective>(c.t).source, end);
},
}, construct.u);
Expand Down Expand Up @@ -651,6 +658,12 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
std::string line;
int lineNum{0};
const auto &instPts{visitor.getInstrumentationPoints()};

// Sanity check: are instrumentation points in the right order?
if (!std::is_sorted(instPts.cbegin(), instPts.cend())) {
DIE("ERROR: Instrumentation points not sorted by line number!\n");
}

auto instIter{instPts.cbegin()};
while (std::getline(inputStream, line)) {
++lineNum;
Expand Down

0 comments on commit 37fee15

Please sign in to comment.