From: Sven Verdoolaege Date: Mon, 23 Dec 2013 09:44:07 +0000 (+0100) Subject: isl_ast_node_print: avoid dangling else warnings on printed AST X-Git-Tag: isl-0.13~98 X-Git-Url: https://repo.or.cz/w/isl.git/commitdiff_plain/21b3e647f0b0511242331c5a5deca68213c6c909 isl_ast_node_print: avoid dangling else warnings on printed AST Some compilers (notably clang) warn about dangling else if an if statement with an else branch appears inside a for loop or another if statement without a surrounding block. Print a block around such if statements to avoid this warning. Signed-off-by: Sven Verdoolaege --- diff --git a/isl_ast.c b/isl_ast.c index 547a7456..c70a0f6f 100644 --- a/isl_ast.c +++ b/isl_ast.c @@ -1479,6 +1479,8 @@ static __isl_give isl_printer *print_ast_node_isl(__isl_take isl_printer *p, * Also if the node is a degenerate for then we will print it as * an assignment followed by the body of the for loop, so we need a block * as well. + * If the node is an if node with an else, then we print a block + * to avoid spurious dangling else warnings emitted by some compilers. */ static int need_block(__isl_keep isl_ast_node *node) { @@ -1486,6 +1488,8 @@ static int need_block(__isl_keep isl_ast_node *node) return 1; if (node->type == isl_ast_node_for && node->u.f.degenerate) return 1; + if (node->type == isl_ast_node_if && node->u.i.else_node) + return 1; return 0; } diff --git a/test_inputs/codegen/atomic3.c b/test_inputs/codegen/atomic3.c index 0bcb9c15..e63e0920 100644 --- a/test_inputs/codegen/atomic3.c +++ b/test_inputs/codegen/atomic3.c @@ -1,7 +1,8 @@ -for (int c0 = 0; c0 <= 64; c0 += 1) +for (int c0 = 0; c0 <= 64; c0 += 1) { if (c0 >= 63) { sync(); } else if (c0 >= 1) { sync(); } else sync(); +} diff --git a/test_inputs/codegen/cloog/pouchet.c b/test_inputs/codegen/cloog/pouchet.c index e2205c96..69027eaf 100644 --- a/test_inputs/codegen/cloog/pouchet.c +++ b/test_inputs/codegen/cloog/pouchet.c @@ -1,5 +1,5 @@ for (int c0 = 1; c0 <= floord(Ny, 2) + 2; c0 += 1) - for (int c1 = max(c0 / 2 + 1, c0 - 1); c1 <= min(c0, (Ny + 2 * c0) / 4); c1 += 1) + for (int c1 = max(c0 / 2 + 1, c0 - 1); c1 <= min(c0, (Ny + 2 * c0) / 4); c1 += 1) { if (Ny + 2 * c0 >= 4 * c1 + 1) { for (int c2 = 1; c2 <= 2; c2 += 1) { S1(c0 - c1, c1, 2 * c0 - 2 * c1, -2 * c0 + 4 * c1, c2); @@ -8,3 +8,4 @@ for (int c0 = 1; c0 <= floord(Ny, 2) + 2; c0 += 1) } else for (int c2 = 1; c2 <= 2; c2 += 1) S2((-Ny + 2 * c0) / 4, (Ny + 2 * c0) / 4, (-Ny / 2) + c0, Ny - 1, c2); + } diff --git a/test_inputs/codegen/dwt.c b/test_inputs/codegen/dwt.c index daec6f79..52adb5d6 100644 --- a/test_inputs/codegen/dwt.c +++ b/test_inputs/codegen/dwt.c @@ -1,7 +1,8 @@ -for (int c0 = 0; c0 < Ncl; c0 += 1) +for (int c0 = 0; c0 < Ncl; c0 += 1) { if (Ncl >= c0 + 2 && c0 >= 1) { S(c0, 28); } else if (c0 == 0) { S(0, 26); } else S(Ncl - 1, 27); +} diff --git a/test_inputs/codegen/omega/if_then-2.c b/test_inputs/codegen/omega/if_then-2.c index b372c862..d1ce579a 100644 --- a/test_inputs/codegen/omega/if_then-2.c +++ b/test_inputs/codegen/omega/if_then-2.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 100; c0 += 1) +for (int c0 = 1; c0 <= 100; c0 += 1) { if (n >= 2) { s0(c0); for (int c1 = 1; c1 <= 100; c1 += 1) { @@ -8,3 +8,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) } else for (int c1 = 1; c1 <= 100; c1 += 1) s2(c0, c1); +} diff --git a/test_inputs/codegen/omega/lift1-1.c b/test_inputs/codegen/omega/lift1-1.c index a32e25fa..3910e4f2 100644 --- a/test_inputs/codegen/omega/lift1-1.c +++ b/test_inputs/codegen/omega/lift1-1.c @@ -1,7 +1,7 @@ for (int c0 = 1; c0 <= 100; c0 += 1) for (int c1 = 1; c1 <= 100; c1 += 1) for (int c2 = 1; c2 <= 100; c2 += 1) - for (int c3 = 1; c3 <= 100; c3 += 1) + for (int c3 = 1; c3 <= 100; c3 += 1) { if (c0 >= 61) { for (int c4 = 1; c4 <= 100; c4 += 1) s1(c0, c1, c2, c3, c4); @@ -10,3 +10,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift1-2.c b/test_inputs/codegen/omega/lift1-2.c index aae7bfca..8737f3c5 100644 --- a/test_inputs/codegen/omega/lift1-2.c +++ b/test_inputs/codegen/omega/lift1-2.c @@ -1,6 +1,6 @@ for (int c0 = 1; c0 <= 100; c0 += 1) for (int c1 = 1; c1 <= 100; c1 += 1) - for (int c2 = 1; c2 <= 100; c2 += 1) + for (int c2 = 1; c2 <= 100; c2 += 1) { if (c0 >= 61) { for (int c3 = 1; c3 <= 100; c3 += 1) for (int c4 = 1; c4 <= 100; c4 += 1) @@ -11,3 +11,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift1-3.c b/test_inputs/codegen/omega/lift1-3.c index de9025bc..4d73f89d 100644 --- a/test_inputs/codegen/omega/lift1-3.c +++ b/test_inputs/codegen/omega/lift1-3.c @@ -1,5 +1,5 @@ for (int c0 = 1; c0 <= 100; c0 += 1) - for (int c1 = 1; c1 <= 100; c1 += 1) + for (int c1 = 1; c1 <= 100; c1 += 1) { if (c0 >= 61) { for (int c2 = 1; c2 <= 100; c2 += 1) for (int c3 = 1; c3 <= 100; c3 += 1) @@ -12,3 +12,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift1-4.c b/test_inputs/codegen/omega/lift1-4.c index 1b859698..7d2de292 100644 --- a/test_inputs/codegen/omega/lift1-4.c +++ b/test_inputs/codegen/omega/lift1-4.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 100; c0 += 1) +for (int c0 = 1; c0 <= 100; c0 += 1) { if (c0 >= 61) { for (int c1 = 1; c1 <= 100; c1 += 1) for (int c2 = 1; c2 <= 100; c2 += 1) @@ -13,3 +13,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } +} diff --git a/test_inputs/codegen/omega/lift2-1.c b/test_inputs/codegen/omega/lift2-1.c index e799eae2..f914743e 100644 --- a/test_inputs/codegen/omega/lift2-1.c +++ b/test_inputs/codegen/omega/lift2-1.c @@ -1,7 +1,7 @@ for (int c0 = 1; c0 <= 100; c0 += 1) for (int c1 = 1; c1 <= 100; c1 += 1) for (int c2 = 1; c2 <= 100; c2 += 1) - for (int c3 = 1; c3 <= 100; c3 += 1) + for (int c3 = 1; c3 <= 100; c3 += 1) { if (c0 >= 61) { for (int c4 = 1; c4 <= 100; c4 += 1) s1(c0, c1, c2, c3, c4); @@ -13,3 +13,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift2-2.c b/test_inputs/codegen/omega/lift2-2.c index 429733ae..8b6dbafc 100644 --- a/test_inputs/codegen/omega/lift2-2.c +++ b/test_inputs/codegen/omega/lift2-2.c @@ -1,6 +1,6 @@ for (int c0 = 1; c0 <= 100; c0 += 1) for (int c1 = 1; c1 <= 100; c1 += 1) - for (int c2 = 1; c2 <= 100; c2 += 1) + for (int c2 = 1; c2 <= 100; c2 += 1) { if (c0 >= 61) { for (int c3 = 1; c3 <= 100; c3 += 1) for (int c4 = 1; c4 <= 100; c4 += 1) @@ -15,3 +15,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift2-3.c b/test_inputs/codegen/omega/lift2-3.c index b0818f1a..1a5954a8 100644 --- a/test_inputs/codegen/omega/lift2-3.c +++ b/test_inputs/codegen/omega/lift2-3.c @@ -1,5 +1,5 @@ for (int c0 = 1; c0 <= 100; c0 += 1) - for (int c1 = 1; c1 <= 100; c1 += 1) + for (int c1 = 1; c1 <= 100; c1 += 1) { if (c0 >= 61) { for (int c2 = 1; c2 <= 100; c2 += 1) for (int c3 = 1; c3 <= 100; c3 += 1) @@ -17,3 +17,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } + } diff --git a/test_inputs/codegen/omega/lift2-4.c b/test_inputs/codegen/omega/lift2-4.c index 5437c17c..d1d04d65 100644 --- a/test_inputs/codegen/omega/lift2-4.c +++ b/test_inputs/codegen/omega/lift2-4.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 100; c0 += 1) +for (int c0 = 1; c0 <= 100; c0 += 1) { if (c0 >= 61) { for (int c1 = 1; c1 <= 100; c1 += 1) for (int c2 = 1; c2 <= 100; c2 += 1) @@ -19,3 +19,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) s1(c0, c1, c2, c3, c4); s0(c0, c1, c2, c3, c4); } +} diff --git a/test_inputs/codegen/omega/m1-1.c b/test_inputs/codegen/omega/m1-1.c index 8f57f56f..07b91f79 100644 --- a/test_inputs/codegen/omega/m1-1.c +++ b/test_inputs/codegen/omega/m1-1.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 9; c0 += 1) +for (int c0 = 1; c0 <= 9; c0 += 1) { if (c0 >= 6) { for (int c1 = 1; c1 <= 9; c1 += 1) s0(c0, c1); @@ -10,3 +10,4 @@ for (int c0 = 1; c0 <= 9; c0 += 1) s0(5, c1); s1(5, c1); } +} diff --git a/test_inputs/codegen/omega/m10-1.c b/test_inputs/codegen/omega/m10-1.c index d57375ed..0b2851f9 100644 --- a/test_inputs/codegen/omega/m10-1.c +++ b/test_inputs/codegen/omega/m10-1.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 18; c0 += 1) +for (int c0 = 1; c0 <= 18; c0 += 1) { if (c0 <= 9 && c0 >= 2) { for (int c1 = 1; c1 <= 9; c1 += 1) { if (c0 % 2 == 0) @@ -11,3 +11,4 @@ for (int c0 = 1; c0 <= 18; c0 += 1) } else if (c0 % 2 == 0) for (int c1 = 1; c1 <= 9; c1 += 1) s0(c1, c0 / 2); +} diff --git a/test_inputs/codegen/omega/m2-0.c b/test_inputs/codegen/omega/m2-0.c index 97fcb7b5..669f51a7 100644 --- a/test_inputs/codegen/omega/m2-0.c +++ b/test_inputs/codegen/omega/m2-0.c @@ -1,4 +1,4 @@ -for (int c0 = 2; c0 <= 9; c0 += 1) +for (int c0 = 2; c0 <= 9; c0 += 1) { if (c0 >= 5) { s1(c0, 1); for (int c1 = 2; c1 <= 9; c1 += 1) { @@ -8,3 +8,4 @@ for (int c0 = 2; c0 <= 9; c0 += 1) } else for (int c1 = 2; c1 <= 9; c1 += 1) s0(c0, c1); +} diff --git a/test_inputs/codegen/omega/m7-1.c b/test_inputs/codegen/omega/m7-1.c index 690dc506..a01856e4 100644 --- a/test_inputs/codegen/omega/m7-1.c +++ b/test_inputs/codegen/omega/m7-1.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 9; c0 += 1) +for (int c0 = 1; c0 <= 9; c0 += 1) { if (c0 % 2 == 0) { for (int c1 = 1; c1 <= 9; c1 += 1) { s0(c1, c0); @@ -7,3 +7,4 @@ for (int c0 = 1; c0 <= 9; c0 += 1) } else for (int c1 = 1; c1 <= 9; c1 += 1) s0(c1, c0); +} diff --git a/test_inputs/codegen/omega/m8-1.c b/test_inputs/codegen/omega/m8-1.c index a36f516e..51c77dae 100644 --- a/test_inputs/codegen/omega/m8-1.c +++ b/test_inputs/codegen/omega/m8-1.c @@ -1,4 +1,4 @@ -for (int c0 = 2; c0 <= 8; c0 += 2) +for (int c0 = 2; c0 <= 8; c0 += 2) { if (c0 % 4 == 0) { for (int c1 = 1; c1 <= 9; c1 += 1) { s0(c1, c0); @@ -7,3 +7,4 @@ for (int c0 = 2; c0 <= 8; c0 += 2) } else for (int c1 = 1; c1 <= 9; c1 += 1) s1(c1, c0); +} diff --git a/test_inputs/codegen/omega/p.delft2-0.c b/test_inputs/codegen/omega/p.delft2-0.c index 714c0f13..1b99a92a 100644 --- a/test_inputs/codegen/omega/p.delft2-0.c +++ b/test_inputs/codegen/omega/p.delft2-0.c @@ -4,8 +4,9 @@ if (P2 <= 3 && P2 >= 0 && P1 <= 3 && P1 >= 0) for (int c2 = 0; c2 <= 7; c2 += 1) if ((5 * c0 + 2 * c2 + 5) % 9 <= 2) for (int c3 = 0; c3 <= 7; c3 += 1) - if ((5 * P2 + 2 * c3) % 9 <= 3) + if ((5 * P2 + 2 * c3) % 9 <= 3) { if (c0 + 1 == P1 && (5 * P1 + 2 * c2) % 9 <= 2 && P1 >= 1) { s0(P1 - 1, P2, c2, c3, ((5 * P1 + 2 * c2) % 9) + 1, (-4 * P2 + 2 * c3 + 9) % 9); } else if (c2 % 4 == 0 && c0 == 3 && P1 == 0) s0(3, P2, c2, c3, (-c2 / 4) + 3, (-4 * P2 + 2 * c3 + 9) % 9); + } diff --git a/test_inputs/codegen/omega/stride7-0.c b/test_inputs/codegen/omega/stride7-0.c index ba476896..7fe17588 100644 --- a/test_inputs/codegen/omega/stride7-0.c +++ b/test_inputs/codegen/omega/stride7-0.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 36; c0 += 1) +for (int c0 = 1; c0 <= 36; c0 += 1) { if (c0 <= 3) { for (int c1 = 1; c1 <= 9; c1 += 1) s1(c1, c0); @@ -11,3 +11,4 @@ for (int c0 = 1; c0 <= 36; c0 += 1) } else if (c0 % 4 == 0) for (int c1 = 1; c1 <= 9; c1 += 1) s0(c1, c0 / 4); +} diff --git a/test_inputs/codegen/omega/ts1d-check-sblock-0.c b/test_inputs/codegen/omega/ts1d-check-sblock-0.c index 0a75c9ab..56a10ca2 100644 --- a/test_inputs/codegen/omega/ts1d-check-sblock-0.c +++ b/test_inputs/codegen/omega/ts1d-check-sblock-0.c @@ -1,11 +1,12 @@ { - for (int c1 = 0; c1 <= 1; c1 += 1) + for (int c1 = 0; c1 <= 1; c1 += 1) { if (c1 == 1) { s0(1, 1, 1, 0, 0); s0(1, 1, 1, N - 1, 0); } else for (int c3 = 0; c3 < N; c3 += 1) s0(1, 0, 1, c3, 0); + } for (int c1 = 0; c1 <= floord(T - 1, 1000); c1 += 1) for (int c2 = 1000 * c1 + 1; c2 <= min(N + T - 3, N + 1000 * c1 + 997); c2 += 1) for (int c3 = max(-N - 1000 * c1 + c2 + 2, 0); c3 <= min(min(999, T - 1000 * c1 - 1), -1000 * c1 + c2 - 1); c3 += 1) diff --git a/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c b/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c index ca440248..5639a733 100644 --- a/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c +++ b/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c @@ -1,12 +1,13 @@ { for (int c1 = -1; c1 < (T >= 1 ? T : 0); c1 += 1) - for (int c2 = 0; c2 < N; c2 += 1) + for (int c2 = 0; c2 < N; c2 += 1) { if (c2 == 0 && T >= c1 + 1 && c1 >= 0) { s0(1, c1, 0, 0, 0); } else if (c2 + 1 == N && T >= c1 + 1 && c1 >= 0) { s0(1, c1, N - 1, 0, 0); } else if (c1 == -1 && c2 >= 0 && N >= c2 + 1) s0(1, -1, c2, 0, 0); + } for (int c1 = 0; c1 <= floord(T - 1, 500); c1 += 1) { for (int c3 = -((c1 + 9) / 8) + 2; c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1) for (int c4 = max(1000 * c1 + 4000 * c3 - 3999, 500 * c1 + 1); c4 <= min(min(2 * N - 4000 * c3 + 3995, N + T - 3), 1000 * c1 + 4000 * c3 - 3000); c4 += 1) diff --git a/test_inputs/codegen/omega/wak2-1.c b/test_inputs/codegen/omega/wak2-1.c index a689e348..56fc8a6e 100644 --- a/test_inputs/codegen/omega/wak2-1.c +++ b/test_inputs/codegen/omega/wak2-1.c @@ -7,7 +7,7 @@ for (int c1_0 = c1; c1_0 <= d1; c1_0 += 1) s0(c0, c1_0); } else - for (int c0 = a2; c0 <= b2; c0 += 1) + for (int c0 = a2; c0 <= b2; c0 += 1) { if (a1 >= c0 + 1) { for (int c1_0 = c2; c1_0 <= d2; c1_0 += 1) s1(c0, c1_0); @@ -28,6 +28,7 @@ for (int c1_0 = max(max(d1 + 1, c1), c2); c1_0 <= d2; c1_0 += 1) s1(c0, c1_0); } + } for (int c0 = max(max(a1, a2), b2 + 1); c0 <= b1; c0 += 1) for (int c1_0 = c1; c1_0 <= d1; c1_0 += 1) s0(c0, c1_0); diff --git a/test_inputs/codegen/pldi2012/figure7_c.c b/test_inputs/codegen/pldi2012/figure7_c.c index b372c862..d1ce579a 100644 --- a/test_inputs/codegen/pldi2012/figure7_c.c +++ b/test_inputs/codegen/pldi2012/figure7_c.c @@ -1,4 +1,4 @@ -for (int c0 = 1; c0 <= 100; c0 += 1) +for (int c0 = 1; c0 <= 100; c0 += 1) { if (n >= 2) { s0(c0); for (int c1 = 1; c1 <= 100; c1 += 1) { @@ -8,3 +8,4 @@ for (int c0 = 1; c0 <= 100; c0 += 1) } else for (int c1 = 1; c1 <= 100; c1 += 1) s2(c0, c1); +} diff --git a/test_inputs/codegen/separation_class4.c b/test_inputs/codegen/separation_class4.c index f9b4ccf0..4b10b5ca 100644 --- a/test_inputs/codegen/separation_class4.c +++ b/test_inputs/codegen/separation_class4.c @@ -1,4 +1,4 @@ -for (int c0 = 0; c0 <= 128; c0 += 1) +for (int c0 = 0; c0 <= 128; c0 += 1) { if (c0 <= 127) { if (c0 == 0) { for (int c3 = 0; c3 <= 1; c3 += 1) @@ -17,3 +17,4 @@ for (int c0 = 0; c0 <= 128; c0 += 1) for (int c3 = 510; c3 <= 511; c3 += 1) for (int c5 = -c3 + 569; c5 < c3 - 449; c5 += 1) S_0(c3, c5); +} diff --git a/test_inputs/codegen/shift2.c b/test_inputs/codegen/shift2.c index 3e2e69b0..beffb463 100644 --- a/test_inputs/codegen/shift2.c +++ b/test_inputs/codegen/shift2.c @@ -45,9 +45,10 @@ for (int c0 = 0; c0 <= 1; c0 += 1) { S_4(c0); } if (length <= 1) - for (int c5 = 0; c5 <= length; c5 += 1) + for (int c5 = 0; c5 <= length; c5 += 1) { if (c5 == length) { S_4(c0); } else S_0(c0, 0, 0); + } }