Skip to content

Fix StmtClone and loop restore-tracker guard for SmallPT AD. - #1876

Open
a-elrawy wants to merge 1 commit into
vgvassilev:masterfrom
a-elrawy:gsoc/smallpt-clad-fixes
Open

Fix StmtClone and loop restore-tracker guard for SmallPT AD.#1876
a-elrawy wants to merge 1 commit into
vgvassilev:masterfrom
a-elrawy:gsoc/smallpt-clad-fixes

Conversation

@a-elrawy

@a-elrawy a-elrawy commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Deep-clone CXX construct/temporary expression arguments in StmtClone. Disable restore-tracker reverse_forw inside loops when no tracker is set. Add StmtCloneConstructRepro and ReverseModeLoopPullbackRepro lit tests.

Copilot AI review requested due to automatic review settings July 7, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two reverse-mode AD stability issues in Clad’s AST cloning and reverse-forward pass handling, and adds regression tests to prevent reintroducing the crashes observed in SmallPT-like code patterns.

Changes:

  • Deep-clone argument expressions for CXXConstructExpr and CXXTemporaryObjectExpr in StmtClone to avoid sharing/mis-owning subexpressions.
  • Add a loop guard in reverse-mode call handling to disable restore_tracker-dependent reverse-forward behavior when no tracker is available.
  • Add two lit regression tests covering the constructor/temporary-arg cloning crash and the loop pullback scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/Differentiator/StmtClone.cpp Deep-clones constructor/temporary-object arguments when cloning AST expressions.
lib/Differentiator/ReverseModeVisitor.cpp Guards reverse-forward restore-tracker usage inside loops when no tracker is set.
test/Gradient/StmtCloneConstructRepro.C New regression test reproducing the CXXTemporaryObjectExpr-argument cloning crash.
test/Gradient/ReverseModeLoopPullbackRepro.C New regression test for reverse-mode behavior in an infinite-loop style SmallPT pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/Gradient/StmtCloneConstructRepro.C
Comment thread test/Gradient/ReverseModeLoopPullbackRepro.C
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@a-elrawy
a-elrawy force-pushed the gsoc/smallpt-clad-fixes branch from 1f79e3b to e75f775 Compare July 7, 2026 23:10
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

Deep-clone CXX construct/temporary expression arguments in StmtClone.
Disable restore-tracker reverse_forw inside loops when no tracker is set.
Add StmtCloneConstructRepro and ReverseModeLoopPullbackRepro lit tests.
Run the loop repro binary so the guard is checked at runtime, not only compile time.
@a-elrawy
a-elrawy force-pushed the gsoc/smallpt-clad-fixes branch from e75f775 to 9d2f80c Compare July 8, 2026 00:20
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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

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