File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3794,12 +3794,18 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
37943794 auto * decl = VDDiff.getDecl ();
37953795 if (VD ->getInit ()) {
37963796 auto * declRef = BuildDeclRef (decl);
3797+ Expr* init = decl->getInit ();
3798+ const auto * CE = dyn_cast_or_null<CXXConstructExpr>(
3799+ init ? init->IgnoreImplicit () : nullptr );
3800+ if (!init ||
3801+ (CE && !CE ->getNumArgs () && !CE ->isListInitialization ()))
3802+ init = getZeroInit (VD ->getType ());
37973803 Expr* assignment = nullptr ;
37983804 if (isa<ArrayType>(VD ->getType ()))
3799- assignment = BuildArrayAssignment (declRef, decl-> getInit (),
3800- direction::forward);
3805+ assignment =
3806+ BuildArrayAssignment (declRef, init, direction::forward);
38013807 else
3802- assignment = BuildOp (BO_Assign, declRef, decl-> getInit () );
3808+ assignment = BuildOp (BO_Assign, declRef, init );
38033809 if (isInsideLoop) {
38043810 if (m_DiffReq.shouldBeRecorded (DS )) {
38053811 auto pushPop = StoreAndRestore (declRef, /* prefix=*/ " _t" ,
Original file line number Diff line number Diff line change 1+ // RUN: %cladclang -fsyntax-only %s -I%S/../../include 2>&1 | %filecheck %s
2+
3+ #include " clad/Differentiator/Differentiator.h"
4+
5+ struct Struct {
6+ double val;
7+ };
8+
9+ void fn (double a) {
10+ for (int i = 0 ; i < 1 ; ++i) {
11+ Struct s;
12+ }
13+ }
14+
15+ int main () {
16+ auto grad = clad::gradient (fn);
17+ }
18+
19+ // CHECK-LABEL: void fn_grad
20+ // CHECK: for (i = 0; i < 1; ++i) {
21+ // CHECK: {{^ *s = \{0\.\};$}}
You can’t perform that action at this time.
0 commit comments