Skip to content

Fix checkpoint loop pragma handling in hessian flows (#1736)#1756

Open
fatfat123-arch wants to merge 1 commit intovgvassilev:masterfrom
fatfat123-arch:fix-1736-checkpoint-loop
Open

Fix checkpoint loop pragma handling in hessian flows (#1736)#1756
fatfat123-arch wants to merge 1 commit intovgvassilev:masterfrom
fatfat123-arch:fix-1736-checkpoint-loop

Conversation

@fatfat123-arch
Copy link

Fixes false-positive #pragma clad checkpoint loop diagnostics in hessian-related flows.

  • I added a regression test: test/Regressions/issue-1736.cpp
  • Also updated tools/ClangPlugin.cpp so dangling checkpoint pragma diagnostics are only emitted when appropriate in hessian/relevant flows, avoiding false positives during hessian scheduling

Passed locally:

  • ninja check-clad-regressions
  • ninja check-clad-diagnostics
  • lit -sv build/test
  • lit -sv build/test/Regressions/issue-1736.cpp

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@vgvassilev
Copy link
Owner

Please address the relevant clang-tidy issues along with valgrind failures.

@fatfat123-arch
Copy link
Author

Please address the relevant clang-tidy issues along with valgrind failures.

Hi @vgvassilev ! I pushed a follow-up commit on this PR: ffbecacd.

It addresses the requested clang-tidy/valgrind-related items in tools/ClangPlugin.cpp:

  • initialize clang::Token NextTok{} (instead of uninitialized token)
  • fix include order/formatting for precheckin

I re-ran local checks and they pass:

  • ninja -C build check-clad
  • ninja -C build check-clad-diagnostics check-clad-regressions check-clad-gradient
  • lit -sv build/test
  • lit -sv build/test/Regressions/issue-1736.cpp
  • lit -sv --param clad_site_config=./lit.site.cfg ../../test/Diagnostics/LoopCheckpointing.C

Could you please approve/re-run the PR workflows for this fork branch so the updated CI checks can execute?
Thanks.

continue;

clang::SourceLocation AfterPragma =
clang::Lexer::getLocForEndOfToken(pair.first, 0, SM, LangOpts);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a better way than using a lexer for this. How does clang do it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback !

I used the lexer lookahead as a temporary minimal fix to validate the root cause quickly, but I agree we should align with Clang’s approach and avoid raw-token peeking here.

Another plan would be to bind #pragma clad checkpoint loop to the immediately following parsed statement and then treat it as valid only for ForStmt / WhileStmt / DoStmt, while keeping diagnoseUnusedPragma for unattached pragma.

Would you recommend implementing this through a dedicated pragma-handler/parser path, or through request-time AST association in Clad? I’d appreciate your guidance on which direction you suggest would be best.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is whatever is done in clang and looks like a lean and simple enough implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it ! Now #pragma clad checkpoint loop is checked against the next parsed statement and accepted only for for / while / do; otherwise it emits the same diagnostic.

Commit: 4d7b61e

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give the relevant clang code that does something similar?

Copy link
Author

@fatfat123-arch fatfat123-arch Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant clang code for the similar behavior is:

  • clang/lib/Parse/ParseStmt.cpp: tok::annot_pragma_loop_hint -> ParsePragmaLoopHint(...)
  • clang/lib/Parse/ParseStmt.cpp: ParsePragmaLoopHint(...) parses the pragma, parses the immediately following statement, and prepends pragma attrs to that statement.
  • clang/lib/Sema/SemaStmtAttr.cpp: handleLoopHintAttr(...) accepts only loop statements and otherwise emits diag::err_pragma_loop_precedes_nonloop.
  • clang/include/clang/Basic/DiagnosticSemaKinds.td: err_pragma_loop_precedes_nonloop.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@fatfat123-arch fatfat123-arch force-pushed the fix-1736-checkpoint-loop branch from 4eb3bf7 to 59eee5f Compare March 11, 2026 09:47
@fatfat123-arch
Copy link
Author

@vgvassilev quick update: I pushed the final fix in commit 59eee5fd (Fix checkpoint loop pragma handling in hessian flows (issue #1736)). At this point, all checks were green except codecov/patch; this commit specifically addresses the uncovered diff lines reported by Codecov. Could you please approve/re-run the workflows for this latest commit so we can get the final CI judgment?
Thank you !

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@fatfat123-arch
Copy link
Author

Quick clarification request: CI is green on this PR, but issue #1736 is already closed. Should this PR still be merged, or should I close it as superseded? @vgvassilev

@fatfat123-arch fatfat123-arch force-pushed the fix-1736-checkpoint-loop branch from 59eee5f to 658cae6 Compare March 17, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants