From 147ec6781301a66cbaa4f8ae5542ef12e9919ee7 Mon Sep 17 00:00:00 2001 From: kchristin Date: Sun, 3 Nov 2024 17:31:54 +0200 Subject: [PATCH] Revert skipping creation of local adjoints for const params and make those non-const --- lib/Differentiator/ReverseModeVisitor.cpp | 4 +--- test/Gradient/Assignments.C | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index db3f87977..b34086b00 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -705,9 +705,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (m_DiffReq.Mode == DiffMode::jacobian && i == m_DiffReq->getNumParams() - 1) continue; - auto VDDerivedType = param->getType(); - if (VDDerivedType.isConstQualified()) - continue; + auto VDDerivedType = getNonConstType(param->getType(), m_Context, m_Sema); // We cannot initialize derived variable for pointer types because // we do not know the correct size. if (utils::isArrayOrPointerType(VDDerivedType)) diff --git a/test/Gradient/Assignments.C b/test/Gradient/Assignments.C index bc2d09cce..99ba93898 100644 --- a/test/Gradient/Assignments.C +++ b/test/Gradient/Assignments.C @@ -826,11 +826,15 @@ double constVal(double y, const double x) { } //CHECK: void constVal_grad_0(double y, const double x, double *_d_y) { +//CHECK-NEXT: double _d_x = 0.; //CHECK-NEXT: double _d_z = 0.; //CHECK-NEXT: const double z = y; //CHECK-NEXT: double _t0 = y; //CHECK-NEXT: y *= z; -//CHECK-NEXT: *_d_y += 1 * x; +//CHECK-NEXT: { +//CHECK-NEXT: *_d_y += 1 * x; +//CHECK-NEXT: _d_x += y * 1; +//CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: y = _t0; //CHECK-NEXT: double _r_d0 = *_d_y;