Fix StmtClone and loop restore-tracker guard for SmallPT AD. - #1876
Open
a-elrawy wants to merge 1 commit into
Open
Fix StmtClone and loop restore-tracker guard for SmallPT AD.#1876a-elrawy wants to merge 1 commit into
a-elrawy wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
CXXConstructExprandCXXTemporaryObjectExprinStmtCloneto 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.
Contributor
|
clang-tidy review says "All clean, LGTM! 👍" |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
a-elrawy
force-pushed
the
gsoc/smallpt-clad-fixes
branch
from
July 7, 2026 23:10
1f79e3b to
e75f775
Compare
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
force-pushed
the
gsoc/smallpt-clad-fixes
branch
from
July 8, 2026 00:20
e75f775 to
9d2f80c
Compare
Contributor
|
clang-tidy review says "All clean, LGTM! 👍" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.