Skip to content

Commit

Permalink
Add a test for declarations in if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
gojakuch committed May 15, 2024
1 parent 86f5f27 commit 1e34c63
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/Gradient/Gradients.C
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,45 @@ double fn_div(double x) {
// CHECK-NEXT: }
// CHECK-NEXT: }

double fn_cond_decl(double x, double y) {
int flag = 1;
if (int cond = flag)
return y*y;
return x*x + y*y;
} // = y^2

//CHECK-NEXT: void fn_cond_decl_grad(double x, double y, double *_d_x, double *_d_y) {
//CHECK-NEXT: int _d_flag = 0;
//CHECK-NEXT: int _d_cond = 0;
//CHECK-NEXT: int cond = 0;
//CHECK-NEXT: bool _cond0;
//CHECK-NEXT: int flag = 1;
//CHECK-NEXT: {
//CHECK-NEXT: _cond0 = cond = flag;
//CHECK-NEXT: if (_cond0)
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: }
//CHECK-NEXT: goto _label1;
//CHECK-NEXT: _label1:
//CHECK-NEXT: {
//CHECK-NEXT: *_d_x += 1 * x;
//CHECK-NEXT: *_d_x += x * 1;
//CHECK-NEXT: *_d_y += 1 * y;
//CHECK-NEXT: *_d_y += y * 1;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: if (_cond0)
//CHECK-NEXT: _label0:
//CHECK-NEXT: {
//CHECK-NEXT: *_d_y += 1 * y;
//CHECK-NEXT: *_d_y += y * 1;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: _d_flag += _d_cond;
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: }

#define TEST(F, x, y) \
{ \
result[0] = 0; \
Expand Down Expand Up @@ -858,4 +897,6 @@ int main() {
INIT_GRADIENT(fn_div);
dx = 0;
TEST_GRADIENT(fn_div, /*numOfDerivativeArgs=*/1, 2, &dx); // CHECK-EXEC: 0.12

INIT_GRADIENT(fn_cond_decl);
}

0 comments on commit 1e34c63

Please sign in to comment.