Skip to content

Fix uninitialized record assignment in reverse mode - #1938

Open
Elvand-Lie wants to merge 1 commit into
vgvassilev:masterfrom
Elvand-Lie:fix-1283-loop-record-initialization
Open

Fix uninitialized record assignment in reverse mode#1938
Elvand-Lie wants to merge 1 commit into
vgvassilev:masterfrom
Elvand-Lie:fix-1283-loop-record-initialization

Conversation

@Elvand-Lie

Copy link
Copy Markdown
Contributor

Summary

  • replace declaration-only empty constructor expressions with Clad’s existing zero initializer before building promoted assignments
  • preserve explicit list initialization and constructor calls with arguments
  • add regression coverage for record declarations inside loops

Testing

  • verified the issue Gradient: Fix missing struct initialization to structs declared inside a loop but not originally initialized #1283 reproducer fails on origin/master and passes with this change
  • manually A/B tested implicit aggregates, default member initializers, explicitly defaulted records, explicit list initialization, and user-defined constructors
  • ran the full lit suite: 174 passed, 1 expected platform failure, 25 unsupported, and 2 failures independently reproduced on origin/master
  • ran DifferentiatorHTests and MiscTests: 5/5 passed
  • ran git-clang-format-18: no changes
  • ran clang-tidy-18 on the changed production-code range: no diagnostics
  • ran git diff --check

Fixes: #1283

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread test/Regressions/issue-1283.cpp Outdated
auto grad = clad::gradient(fn);
}

// CHECK-LABEL: void fn_grad

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why not using CHECK: and CHECK-NEXT? We also need to check the execution results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in a9fe9a5. The regression now uses CHECK/CHECK-NEXT for the generated loop, builds and runs the test executable, and checks the derivative result (6.00) with CHECK-EXEC. I also verified that the revised lit test passes with this patch and fails against current origin/master at the original s = ; line.

@Elvand-Lie
Elvand-Lie force-pushed the fix-1283-loop-record-initialization branch from 1f545c6 to a9fe9a5 Compare August 2, 2026 17:04
@github-actions

github-actions Bot commented Aug 2, 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.

Gradient: Fix missing struct initialization to structs declared inside a loop but not originally initialized

2 participants