diff --git a/test/Gradient/Assignments.C b/test/Gradient/Assignments.C index e63396d87..f40416939 100644 --- a/test/Gradient/Assignments.C +++ b/test/Gradient/Assignments.C @@ -909,6 +909,67 @@ double f19(double a, double b) { //CHECK-NEXT: } //CHECK-NEXT: } +double f20(double x, double y) { + auto& r = x; + r = 3; + x = r * y; + return x; // 3y +} + +//CHECK: void f20_grad(double x, double y, clad::array_ref _d_x, clad::array_ref _d_y) { +//CHECK-NEXT: double *_d_r = 0; +//CHECK-NEXT: double _t0; +//CHECK-NEXT: double _t1; +//CHECK-NEXT: double _t2; +//CHECK-NEXT: _d_r = &* _d_x; +//CHECK-NEXT: double &r = x; +//CHECK-NEXT: _t0 = r; +//CHECK-NEXT: r = 3; +//CHECK-NEXT: _t1 = x; +//CHECK-NEXT: _t2 = y; +//CHECK-NEXT: x = r * _t2; +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: _label0: +//CHECK-NEXT: * _d_x += 1; +//CHECK-NEXT: { +//CHECK-NEXT: x = _t1; +//CHECK-NEXT: double _r_d1 = * _d_x; +//CHECK-NEXT: double _r0 = _r_d1 * _t2; +//CHECK-NEXT: *_d_r += _r0; +//CHECK-NEXT: double _r1 = r * _r_d1; +//CHECK-NEXT: * _d_y += _r1; +//CHECK-NEXT: * _d_x -= _r_d1; +//CHECK-NEXT: * _d_x; +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: r = _t0; +//CHECK-NEXT: double _r_d0 = *_d_r; +//CHECK-NEXT: *_d_r -= _r_d0; +//CHECK-NEXT: } +//CHECK-NEXT: } + +double f21 (double x, double y) { + y = (y++, x); + return y; +} + +//CHECK-NEXT: void f21_grad(double x, double y, clad::array_ref _d_x, clad::array_ref _d_y) { +//CHECK-NEXT: double _t0; +//CHECK-NEXT: _t0 = y; +//CHECK-NEXT: y = (y++ , x); +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: _label0: +//CHECK-NEXT: * _d_y += 1; +//CHECK-NEXT: { +//CHECK-NEXT: y = _t0; +//CHECK-NEXT: double _r_d0 = * _d_y; +//CHECK-NEXT: * _d_y += 0; +//CHECK-NEXT: y--; +//CHECK-NEXT: * _d_x += _r_d0; +//CHECK-NEXT: * _d_y -= _r_d0; +//CHECK-NEXT: * _d_y; +//CHECK-NEXT: } +//CHECK-NEXT: } #define TEST(F, x, y) \ { \ @@ -971,4 +1032,6 @@ int main() { VAR_TEST(f17, "i", 3, 4, 5, &result[0]); // CHECK-EXEC: {2.00} VAR_TEST(f18, "i, j", 3, 4, 5, &result[0], &result[1]); // CHECK-EXEC: {3.00, 2.00} TEST(f19, 1, 2); // CHECK-EXEC: {2.00, 2.00} + TEST(f20, 1, 2); // CHECK-EXEC: {0.00, 3.00} + TEST(f21, 6, 4); // CHECK-EXEC: {1.00, 0.00} } diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index 1bd58a186..818a15c90 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -345,6 +345,52 @@ double f_cond3(double x, double c) { double f_cond3_grad(double x, double c, clad::array_ref _d_x, clad::array_ref _d_y); +double f_cond4(double x, double y) { + int i = 0; + double arr[] = {x, y}; + if (x > 0) { + y = arr[i] * x; + } + return y; +} + +//CHECK: void f_cond4_grad(double x, double y, clad::array_ref _d_x, clad::array_ref _d_y) { +//CHECK-NEXT: int _d_i = 0; +//CHECK-NEXT: clad::array _d_arr(2UL); +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: double _t0; +//CHECK-NEXT: double _t1; +//CHECK-NEXT: int i = 0; +//CHECK-NEXT: double arr[2] = {x, y}; +//CHECK-NEXT: _cond0 = x > 0; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: _t0 = y; +//CHECK-NEXT: _t1 = x; +//CHECK-NEXT: y = arr[i] * _t1; +//CHECK-NEXT: } +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: _label0: +//CHECK-NEXT: * _d_y += 1; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: { +//CHECK-NEXT: y = _t0; +//CHECK-NEXT: double _r_d0 = * _d_y; +//CHECK-NEXT: double _r0 = _r_d0 * _t1; +//CHECK-NEXT: _d_arr[i] += _r0; +//CHECK-NEXT: double _r1 = arr[i] * _r_d0; +//CHECK-NEXT: * _d_x += _r1; +//CHECK-NEXT: * _d_y -= _r_d0; +//CHECK-NEXT: * _d_y; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: * _d_x += _d_arr[0]; +//CHECK-NEXT: * _d_y += _d_arr[1]; +//CHECK-NEXT: } +//CHECK-NEXT: } + +double f_cond4_grad(double x, double c, clad::array_ref _d_x, clad::array_ref _d_y); + double f_if1(double x, double y) { if (x > y) return x; @@ -904,6 +950,7 @@ int main() { TEST(f_cond1, 3, 2); // CHECK-EXEC: Result is = {1.00, 0.00} TEST(f_cond2, 3, -1); // CHECK-EXEC: Result is = {1.00, 0.00} TEST(f_cond3, 3, -1); // CHECK-EXEC: Result is = {1.00, -1.00} + TEST(f_cond4, 3, -1); // CHECK-EXEC: Result is = {6.00, 0.00} TEST(f_if1, 3, 2); // CHECK-EXEC: Result is = {1.00, 0.00} TEST(f_if2, -5, -4); // CHECK-EXEC: Result is = {0.00, -1.00} clad::gradient(&S::f);