* C PATCH to overhaul warning about dangling else (PR c/70436)
@ 2016-04-13 14:14 Marek Polacek
2016-04-13 14:16 ` Jakub Jelinek
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Marek Polacek @ 2016-04-13 14:14 UTC (permalink / raw)
To: GCC Patches, Joseph Myers
I said I'd take care of the C FE part of this PR, so here it is.
As this PR shows, our dangling else warning regressed in such a way that we
weren't warning about cases such as
if (A)
for (;;)
if (B)
bar ();
else
baz ();
The problem was that we were setting FIRST_IF only when an "if" was immediately
followed by an RID_IF token.
I revamped the warning so that it follows what the C++ FE does (i.e. passing
IF_P bools here and there) and it seems to work quite well. I didn't mean to
tackle the OMP bits but I bet it would be just a matter of passing IF_P
somewhere.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-04-13 Marek Polacek <polacek@redhat.com>
PR c/70436
* c-parser.c
(c_parser_statement_after_labels): Add IF_P argument and adjust
callers.
(c_parser_statement): Likewise.
(c_parser_c99_block_statement): Likewise.
(c_parser_while_statement): Likewise.
(c_parser_for_statement): Likewise.
(c_parser_if_body): Don't set IF_P here.
(c_parser_if_statement): Add IF_P argument. Set IF_P here. Warn
about dangling else here.
* c-tree.h (c_finish_if_stmt): Adjust declaration.
* c-typeck.c (c_finish_if_stmt): Remove NESTED_IF parameter. Don't
warn about dangling else here.
* testsuite/gcc.dg/Wparentheses-12.c: New test.
* testsuite/gcc.dg/Wparentheses-13.c: New test.
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 6460684..cafcb99 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -1301,13 +1301,14 @@ static void c_parser_initval (c_parser *, struct c_expr *,
static tree c_parser_compound_statement (c_parser *);
static void c_parser_compound_statement_nostart (c_parser *);
static void c_parser_label (c_parser *);
-static void c_parser_statement (c_parser *);
-static void c_parser_statement_after_labels (c_parser *, vec<tree> * = NULL);
-static void c_parser_if_statement (c_parser *, vec<tree> *);
+static void c_parser_statement (c_parser *, bool *);
+static void c_parser_statement_after_labels (c_parser *, bool *,
+ vec<tree> * = NULL);
+static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
static void c_parser_switch_statement (c_parser *);
-static void c_parser_while_statement (c_parser *, bool);
+static void c_parser_while_statement (c_parser *, bool, bool *);
static void c_parser_do_statement (c_parser *, bool);
-static void c_parser_for_statement (c_parser *, bool);
+static void c_parser_for_statement (c_parser *, bool, bool *);
static tree c_parser_asm_statement (c_parser *);
static tree c_parser_asm_operands (c_parser *);
static tree c_parser_asm_goto_operands (c_parser *);
@@ -4853,7 +4854,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
last_label = false;
last_stmt = true;
mark_valid_location_for_stdc_pragma (false);
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, NULL);
}
parser->error = false;
@@ -5098,22 +5099,25 @@ c_parser_label (c_parser *parser)
*/
static void
-c_parser_statement (c_parser *parser)
+c_parser_statement (c_parser *parser, bool *if_p)
{
c_parser_all_labels (parser);
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, if_p, NULL);
}
/* Parse a statement, other than a labeled statement. CHAIN is a vector
of if-else-if conditions. */
static void
-c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain)
+c_parser_statement_after_labels (c_parser *parser, bool *if_p,
+ vec<tree> *chain)
{
location_t loc = c_parser_peek_token (parser)->location;
tree stmt = NULL_TREE;
bool in_if_block = parser->in_if_block;
parser->in_if_block = false;
+ if (if_p != NULL)
+ *if_p = false;
switch (c_parser_peek_token (parser)->type)
{
case CPP_OPEN_BRACE:
@@ -5123,19 +5127,19 @@ c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain)
switch (c_parser_peek_token (parser)->keyword)
{
case RID_IF:
- c_parser_if_statement (parser, chain);
+ c_parser_if_statement (parser, if_p, chain);
break;
case RID_SWITCH:
c_parser_switch_statement (parser);
break;
case RID_WHILE:
- c_parser_while_statement (parser, false);
+ c_parser_while_statement (parser, false, if_p);
break;
case RID_DO:
c_parser_do_statement (parser, false);
break;
case RID_FOR:
- c_parser_for_statement (parser, false);
+ c_parser_for_statement (parser, false, if_p);
break;
case RID_CILK_FOR:
if (!flag_cilkplus)
@@ -5324,11 +5328,11 @@ c_parser_paren_condition (c_parser *parser)
/* Parse a statement which is a block in C99. */
static tree
-c_parser_c99_block_statement (c_parser *parser)
+c_parser_c99_block_statement (c_parser *parser, bool *if_p)
{
tree block = c_begin_compound_stmt (flag_isoc99);
location_t loc = c_parser_peek_token (parser)->location;
- c_parser_statement (parser);
+ c_parser_statement (parser, if_p);
return c_end_compound_stmt (loc, block, flag_isoc99);
}
@@ -5350,7 +5354,6 @@ c_parser_if_body (c_parser *parser, bool *if_p,
= get_token_indent_info (c_parser_peek_token (parser));
c_parser_all_labels (parser);
- *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
location_t loc = c_parser_peek_token (parser)->location;
@@ -5363,7 +5366,7 @@ c_parser_if_body (c_parser *parser, bool *if_p,
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
add_stmt (c_parser_compound_statement (parser));
else
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, if_p);
token_indent_info next_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
@@ -5397,7 +5400,7 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
c_parser_consume_token (parser);
}
else
- c_parser_statement_after_labels (parser, chain);
+ c_parser_statement_after_labels (parser, NULL, chain);
token_indent_info next_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
@@ -5415,12 +5418,12 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
CHAIN is a vector of if-else-if conditions. */
static void
-c_parser_if_statement (c_parser *parser, vec<tree> *chain)
+c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
{
tree block;
location_t loc;
tree cond;
- bool first_if = false;
+ bool nested_if = false;
tree first_body, second_body;
bool in_if_block;
tree if_stmt;
@@ -5439,7 +5442,7 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
}
in_if_block = parser->in_if_block;
parser->in_if_block = true;
- first_body = c_parser_if_body (parser, &first_if, if_tinfo);
+ first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
parser->in_if_block = in_if_block;
if (warn_duplicated_cond)
@@ -5470,10 +5473,22 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
}
}
second_body = c_parser_else_body (parser, else_tinfo, chain);
+ /* Set IF_P to true to indicate that this if statement has an
+ else clause. This may trigger the Wparentheses warning
+ below when we get back up to the parent if statement. */
+ if (if_p != NULL)
+ *if_p = true;
}
else
{
second_body = NULL_TREE;
+
+ /* Diagnose an ambiguous else if if-then-else is nested inside
+ if-then. */
+ if (nested_if)
+ warning_at (loc, OPT_Wparentheses,
+ "suggest explicit braces to avoid ambiguous %<else%>");
+
if (warn_duplicated_cond)
{
/* This if statement does not have an else clause. We don't
@@ -5482,7 +5497,7 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
chain = NULL;
}
}
- c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
+ c_finish_if_stmt (loc, cond, first_body, second_body);
if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
/* If the if statement contains array notations, then we expand them. */
@@ -5533,7 +5548,7 @@ c_parser_switch_statement (c_parser *parser)
c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
save_break = c_break_label;
c_break_label = NULL_TREE;
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, NULL/*if??*/);
c_finish_case (body, ce.original_type);
if (c_break_label)
{
@@ -5553,7 +5568,7 @@ c_parser_switch_statement (c_parser *parser)
*/
static void
-c_parser_while_statement (c_parser *parser, bool ivdep)
+c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p)
{
tree block, cond, body, save_break, save_cont;
location_t loc;
@@ -5580,7 +5595,7 @@ c_parser_while_statement (c_parser *parser, bool ivdep)
token_indent_info body_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, if_p);
c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
@@ -5615,7 +5630,7 @@ c_parser_do_statement (c_parser *parser, bool ivdep)
c_break_label = NULL_TREE;
save_cont = c_cont_label;
c_cont_label = NULL_TREE;
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, NULL);
c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
new_break = c_break_label;
c_break_label = save_break;
@@ -5693,7 +5708,7 @@ c_parser_do_statement (c_parser *parser, bool ivdep)
*/
static void
-c_parser_for_statement (c_parser *parser, bool ivdep)
+c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p)
{
tree block, cond, incr, save_break, save_cont, body;
/* The following are only used when parsing an ObjC foreach statement. */
@@ -5869,7 +5884,7 @@ c_parser_for_statement (c_parser *parser, bool ivdep)
token_indent_info body_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, if_p);
if (is_foreach_statement)
objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
@@ -10118,9 +10133,9 @@ c_parser_pragma (c_parser *parser, enum pragma_context context)
return false;
}
if (c_parser_next_token_is_keyword (parser, RID_FOR))
- c_parser_for_statement (parser, true);
+ c_parser_for_statement (parser, true, NULL);
else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
- c_parser_while_statement (parser, true);
+ c_parser_while_statement (parser, true, NULL);
else
c_parser_do_statement (parser, true);
return false;
@@ -13441,7 +13456,7 @@ static tree
c_parser_omp_structured_block (c_parser *parser)
{
tree stmt = push_stmt_list ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
return pop_stmt_list (stmt);
}
@@ -14843,7 +14858,7 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
add_stmt (c_end_compound_stmt (here, stmt, true));
}
else
- add_stmt (c_parser_c99_block_statement (parser));
+ add_stmt (c_parser_c99_block_statement (parser, NULL));
if (c_cont_label)
{
tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
@@ -15397,7 +15412,7 @@ c_parser_omp_parallel (location_t loc, c_parser *parser,
}
block = c_begin_omp_parallel ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
stmt = c_finish_omp_parallel (loc, clauses, block);
return stmt;
@@ -15458,7 +15473,7 @@ c_parser_omp_task (location_t loc, c_parser *parser)
"#pragma omp task");
block = c_begin_omp_task ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
return c_finish_omp_task (loc, clauses, block);
}
diff --git gcc/c/c-tree.h gcc/c/c-tree.h
index 96ab049..d559207 100644
--- gcc/c/c-tree.h
+++ gcc/c/c-tree.h
@@ -641,7 +641,7 @@ extern tree build_asm_stmt (tree, tree);
extern int c_types_compatible_p (tree, tree);
extern tree c_begin_compound_stmt (bool);
extern tree c_end_compound_stmt (location_t, tree, bool);
-extern void c_finish_if_stmt (location_t, tree, tree, tree, bool);
+extern void c_finish_if_stmt (location_t, tree, tree, tree);
extern void c_finish_loop (location_t, tree, tree, tree, tree, tree, bool);
extern tree c_begin_stmt_expr (void);
extern tree c_finish_stmt_expr (location_t, tree);
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index fb274d5..9a14994 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -9974,12 +9974,11 @@ c_finish_case (tree body, tree type)
\f
/* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
- may be null. NESTED_IF is true if THEN_BLOCK contains another IF
- statement, and was not surrounded with parenthesis. */
+ may be null. */
void
c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
- tree else_block, bool nested_if)
+ tree else_block)
{
tree stmt;
@@ -10011,39 +10010,6 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
return;
}
}
- /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */
- if (warn_parentheses && nested_if && else_block == NULL)
- {
- tree inner_if = then_block;
-
- /* We know from the grammar productions that there is an IF nested
- within THEN_BLOCK. Due to labels and c99 conditional declarations,
- it might not be exactly THEN_BLOCK, but should be the last
- non-container statement within. */
- while (1)
- switch (TREE_CODE (inner_if))
- {
- case COND_EXPR:
- goto found;
- case BIND_EXPR:
- inner_if = BIND_EXPR_BODY (inner_if);
- break;
- case STATEMENT_LIST:
- inner_if = expr_last (then_block);
- break;
- case TRY_FINALLY_EXPR:
- case TRY_CATCH_EXPR:
- inner_if = TREE_OPERAND (inner_if, 0);
- break;
- default:
- gcc_unreachable ();
- }
- found:
-
- if (COND_EXPR_ELSE (inner_if))
- warning_at (if_locus, OPT_Wparentheses,
- "suggest explicit braces to avoid ambiguous %<else%>");
- }
stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
SET_EXPR_LOCATION (stmt, if_locus);
diff --git gcc/testsuite/gcc.dg/Wparentheses-12.c gcc/testsuite/gcc.dg/Wparentheses-12.c
index e69de29..7832415 100644
--- gcc/testsuite/gcc.dg/Wparentheses-12.c
+++ gcc/testsuite/gcc.dg/Wparentheses-12.c
@@ -0,0 +1,135 @@
+/* PR c/70436 */
+/* { dg-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+foo (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ if (b)
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ while (1)
+ if (a)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ while (1)
+ {
+ if (a) { bar (); } else { baz (); }
+ }
+ else
+ bar ();
+
+ if (a)
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+ else bar ();
+
+ if (a)
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+ else bar ();
+
+ if (a)
+ for (;;)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ for (;;)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ do
+ if (b) bar (); else baz ();
+ while (b);
+
+ if (a)
+ do
+ if (b) bar ();
+ while (b);
+ else baz ();
+}
diff --git gcc/testsuite/gcc.dg/Wparentheses-13.c gcc/testsuite/gcc.dg/Wparentheses-13.c
index e69de29..9837ba5 100644
--- gcc/testsuite/gcc.dg/Wparentheses-13.c
+++ gcc/testsuite/gcc.dg/Wparentheses-13.c
@@ -0,0 +1,67 @@
+/* PR c/70436 */
+/* { dg-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (int);
+
+void
+foo (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ if (b)
+ {
+ if (c)
+ bar (0);
+ }
+ else
+ bar (1);
+
+ if (a > 0)
+ if (a > 1)
+ if (a > 2)
+ if (a > 3)
+ if (a > 4)
+ if (a > 5) /* { dg-warning "ambiguous" } */
+ if (a > 6)
+ while (1)
+ bar (0);
+ else
+ bar (1);
+
+ if (a) /* { dg-warning "ambiguous" } */
+ if (b)
+ switch (c);
+ else
+ bar (1);
+
+ switch (a)
+ {
+ default:
+ if (b) /* { dg-warning "ambiguous" } */
+ if (c)
+ for (;;)
+ bar (0);
+ else
+ bar (1);
+ }
+
+ if (a) /* { dg-warning "ambiguous" } */
+ if (a)
+ {
+ bar (2);
+ }
+ else
+ bar (3);
+
+ if (a)
+ do if (b) bar (4); while (1);
+ else bar (5);
+
+ do
+ {
+ if (a)
+ if (b) /* { dg-warning "ambiguous" } */
+ if (c) for (;;) bar (6);
+ else bar (7);
+ } while (0);
+}
Marek
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
@ 2016-04-13 14:16 ` Jakub Jelinek
2016-04-13 14:19 ` Marek Polacek
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2016-04-13 14:16 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 04:14:03PM +0200, Marek Polacek wrote:
> I said I'd take care of the C FE part of this PR, so here it is.
>
> As this PR shows, our dangling else warning regressed in such a way that we
> weren't warning about cases such as
>
> if (A)
> for (;;)
> if (B)
> bar ();
> else
> baz ();
>
> The problem was that we were setting FIRST_IF only when an "if" was immediately
> followed by an RID_IF token.
>
> I revamped the warning so that it follows what the C++ FE does (i.e. passing
> IF_P bools here and there) and it seems to work quite well. I didn't mean to
> tackle the OMP bits but I bet it would be just a matter of passing IF_P
> somewhere.
I'll look at the OMP bits both for C and C++ once/if this is committed.
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
2016-04-13 14:16 ` Jakub Jelinek
@ 2016-04-13 14:19 ` Marek Polacek
2016-04-13 15:00 ` Bernd Schmidt
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Marek Polacek @ 2016-04-13 14:19 UTC (permalink / raw)
To: GCC Patches; +Cc: Jakub Jelinek
Looks like Joseph will be on vacation for the next few days so if we
want to get this in sooner, someone else will need to review & approve
the patch.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
2016-04-13 14:16 ` Jakub Jelinek
2016-04-13 14:19 ` Marek Polacek
@ 2016-04-13 15:00 ` Bernd Schmidt
2016-04-13 15:56 ` Marek Polacek
2016-04-13 15:10 ` Jakub Jelinek
2016-04-15 13:07 ` Jakub Jelinek
4 siblings, 1 reply; 9+ messages in thread
From: Bernd Schmidt @ 2016-04-13 15:00 UTC (permalink / raw)
To: Marek Polacek, GCC Patches, Joseph Myers
On 04/13/2016 04:14 PM, Marek Polacek wrote:
> I revamped the warning so that it follows what the C++ FE does (i.e. passing
> IF_P bools here and there) and it seems to work quite well. I didn't mean to
> tackle the OMP bits but I bet it would be just a matter of passing IF_P
> somewhere.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
Ok if you adjust function comments to mention the new argument where
applicable.
Bernd
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
` (2 preceding siblings ...)
2016-04-13 15:00 ` Bernd Schmidt
@ 2016-04-13 15:10 ` Jakub Jelinek
2016-04-13 15:43 ` Marek Polacek
2016-04-15 13:07 ` Jakub Jelinek
4 siblings, 1 reply; 9+ messages in thread
From: Jakub Jelinek @ 2016-04-13 15:10 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 04:14:03PM +0200, Marek Polacek wrote:
> PR c/70436
> * c-parser.c
> (c_parser_statement_after_labels): Add IF_P argument and adjust
> callers.
Can you put
> @@ -5533,7 +5548,7 @@ c_parser_switch_statement (c_parser *parser)
> c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
> save_break = c_break_label;
> c_break_label = NULL_TREE;
> - body = c_parser_c99_block_statement (parser);
> + body = c_parser_c99_block_statement (parser, NULL/*if??*/);
> c_finish_case (body, ce.original_type);
> if (c_break_label)
> {
Is:
void bar (int);
void
foo (int a, int b, int c)
{
if (a)
switch (b)
case 0:
if (c)
bar (1);
else
bar (2);
}
something -Wdangling-else should warn about? Note, g++ does not warn
about it, and clang nor clang++ doesn't either.
As it is something that unlikely happens in user code, I guess it is ok
to not warn about this for GCC 6, and we can deal with that later on.
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 15:10 ` Jakub Jelinek
@ 2016-04-13 15:43 ` Marek Polacek
2016-04-13 15:45 ` Jakub Jelinek
0 siblings, 1 reply; 9+ messages in thread
From: Marek Polacek @ 2016-04-13 15:43 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 05:09:58PM +0200, Jakub Jelinek wrote:
> On Wed, Apr 13, 2016 at 04:14:03PM +0200, Marek Polacek wrote:
> > PR c/70436
> > * c-parser.c
> > (c_parser_statement_after_labels): Add IF_P argument and adjust
> > callers.
>
> Can you put
Were you going to say to put them on the same line? ;)
Done.
> > @@ -5533,7 +5548,7 @@ c_parser_switch_statement (c_parser *parser)
> > c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
> > save_break = c_break_label;
> > c_break_label = NULL_TREE;
> > - body = c_parser_c99_block_statement (parser);
> > + body = c_parser_c99_block_statement (parser, NULL/*if??*/);
> > c_finish_case (body, ce.original_type);
> > if (c_break_label)
> > {
>
> Is:
> void bar (int);
>
> void
> foo (int a, int b, int c)
> {
> if (a)
> switch (b)
> case 0:
> if (c)
> bar (1);
> else
> bar (2);
> }
> something -Wdangling-else should warn about? Note, g++ does not warn
> about it, and clang nor clang++ doesn't either.
> As it is something that unlikely happens in user code, I guess it is ok
> to not warn about this for GCC 6, and we can deal with that later on.
Seems quite artificial in the sense that I wouldn't expect many switch
statements to be lacking {}'s, but also I don't think that the warning
would be inappropriate here. Since I already regtested my patch, I'll
go ahead with that, but sure, could be something to address in the future.
Marek
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 15:43 ` Marek Polacek
@ 2016-04-13 15:45 ` Jakub Jelinek
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2016-04-13 15:45 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 05:43:25PM +0200, Marek Polacek wrote:
> On Wed, Apr 13, 2016 at 05:09:58PM +0200, Jakub Jelinek wrote:
> > On Wed, Apr 13, 2016 at 04:14:03PM +0200, Marek Polacek wrote:
> > > PR c/70436
> > > * c-parser.c
> > > (c_parser_statement_after_labels): Add IF_P argument and adjust
> > > callers.
> >
> > Can you put
>
> Were you going to say to put them on the same line? ;)
> Done.
Sure, thank you for reading my mind. Started thinking about the switch
case in the middle of writing that sentence and forgot about it.
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 15:00 ` Bernd Schmidt
@ 2016-04-13 15:56 ` Marek Polacek
0 siblings, 0 replies; 9+ messages in thread
From: Marek Polacek @ 2016-04-13 15:56 UTC (permalink / raw)
To: Bernd Schmidt; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 05:00:00PM +0200, Bernd Schmidt wrote:
> On 04/13/2016 04:14 PM, Marek Polacek wrote:
> >I revamped the warning so that it follows what the C++ FE does (i.e. passing
> >IF_P bools here and there) and it seems to work quite well. I didn't mean to
> >tackle the OMP bits but I bet it would be just a matter of passing IF_P
> >somewhere.
> >
> >Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> Ok if you adjust function comments to mention the new argument where
> applicable.
I kept telling myself to not forget to add the commentary and I did all the
same. Fixed in the below. Thanks for reviewing!
2016-04-13 Marek Polacek <polacek@redhat.com>
PR c/70436
* c-parser.c (c_parser_statement_after_labels): Add IF_P argument and
adjust callers.
(c_parser_statement): Likewise.
(c_parser_c99_block_statement): Likewise.
(c_parser_while_statement): Likewise.
(c_parser_for_statement): Likewise.
(c_parser_if_body): Don't set IF_P here.
(c_parser_if_statement): Add IF_P argument. Set IF_P here. Warn
about dangling else here.
* c-tree.h (c_finish_if_stmt): Adjust declaration.
* c-typeck.c (c_finish_if_stmt): Remove NESTED_IF parameter. Don't
warn about dangling else here.
* testsuite/gcc.dg/Wparentheses-12.c: New test.
* testsuite/gcc.dg/Wparentheses-13.c: New test.
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 6460684..d37c691 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -1301,13 +1301,14 @@ static void c_parser_initval (c_parser *, struct c_expr *,
static tree c_parser_compound_statement (c_parser *);
static void c_parser_compound_statement_nostart (c_parser *);
static void c_parser_label (c_parser *);
-static void c_parser_statement (c_parser *);
-static void c_parser_statement_after_labels (c_parser *, vec<tree> * = NULL);
-static void c_parser_if_statement (c_parser *, vec<tree> *);
+static void c_parser_statement (c_parser *, bool *);
+static void c_parser_statement_after_labels (c_parser *, bool *,
+ vec<tree> * = NULL);
+static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
static void c_parser_switch_statement (c_parser *);
-static void c_parser_while_statement (c_parser *, bool);
+static void c_parser_while_statement (c_parser *, bool, bool *);
static void c_parser_do_statement (c_parser *, bool);
-static void c_parser_for_statement (c_parser *, bool);
+static void c_parser_for_statement (c_parser *, bool, bool *);
static tree c_parser_asm_statement (c_parser *);
static tree c_parser_asm_operands (c_parser *);
static tree c_parser_asm_goto_operands (c_parser *);
@@ -4853,7 +4854,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
last_label = false;
last_stmt = true;
mark_valid_location_for_stdc_pragma (false);
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, NULL);
}
parser->error = false;
@@ -5095,25 +5096,35 @@ c_parser_label (c_parser *parser)
statement:
transaction-statement
transaction-cancel-statement
-*/
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static void
-c_parser_statement (c_parser *parser)
+c_parser_statement (c_parser *parser, bool *if_p)
{
c_parser_all_labels (parser);
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, if_p, NULL);
}
/* Parse a statement, other than a labeled statement. CHAIN is a vector
- of if-else-if conditions. */
+ of if-else-if conditions.
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static void
-c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain)
+c_parser_statement_after_labels (c_parser *parser, bool *if_p,
+ vec<tree> *chain)
{
location_t loc = c_parser_peek_token (parser)->location;
tree stmt = NULL_TREE;
bool in_if_block = parser->in_if_block;
parser->in_if_block = false;
+ if (if_p != NULL)
+ *if_p = false;
switch (c_parser_peek_token (parser)->type)
{
case CPP_OPEN_BRACE:
@@ -5123,19 +5134,19 @@ c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain)
switch (c_parser_peek_token (parser)->keyword)
{
case RID_IF:
- c_parser_if_statement (parser, chain);
+ c_parser_if_statement (parser, if_p, chain);
break;
case RID_SWITCH:
c_parser_switch_statement (parser);
break;
case RID_WHILE:
- c_parser_while_statement (parser, false);
+ c_parser_while_statement (parser, false, if_p);
break;
case RID_DO:
c_parser_do_statement (parser, false);
break;
case RID_FOR:
- c_parser_for_statement (parser, false);
+ c_parser_for_statement (parser, false, if_p);
break;
case RID_CILK_FOR:
if (!flag_cilkplus)
@@ -5321,14 +5332,18 @@ c_parser_paren_condition (c_parser *parser)
return cond;
}
-/* Parse a statement which is a block in C99. */
+/* Parse a statement which is a block in C99.
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static tree
-c_parser_c99_block_statement (c_parser *parser)
+c_parser_c99_block_statement (c_parser *parser, bool *if_p)
{
tree block = c_begin_compound_stmt (flag_isoc99);
location_t loc = c_parser_peek_token (parser)->location;
- c_parser_statement (parser);
+ c_parser_statement (parser, if_p);
return c_end_compound_stmt (loc, block, flag_isoc99);
}
@@ -5338,7 +5353,11 @@ c_parser_c99_block_statement (c_parser *parser)
we handle an empty body specially for the sake of -Wempty-body
warnings, and (d) we call parser_compound_statement directly
because c_parser_statement_after_labels resets
- parser->in_if_block. */
+ parser->in_if_block.
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static tree
c_parser_if_body (c_parser *parser, bool *if_p,
@@ -5350,7 +5369,6 @@ c_parser_if_body (c_parser *parser, bool *if_p,
= get_token_indent_info (c_parser_peek_token (parser));
c_parser_all_labels (parser);
- *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
location_t loc = c_parser_peek_token (parser)->location;
@@ -5363,7 +5381,7 @@ c_parser_if_body (c_parser *parser, bool *if_p,
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
add_stmt (c_parser_compound_statement (parser));
else
- c_parser_statement_after_labels (parser);
+ c_parser_statement_after_labels (parser, if_p);
token_indent_info next_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
@@ -5397,7 +5415,7 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
c_parser_consume_token (parser);
}
else
- c_parser_statement_after_labels (parser, chain);
+ c_parser_statement_after_labels (parser, NULL, chain);
token_indent_info next_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
@@ -5412,15 +5430,18 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo,
if ( expression ) statement
if ( expression ) statement else statement
- CHAIN is a vector of if-else-if conditions. */
+ CHAIN is a vector of if-else-if conditions.
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static void
-c_parser_if_statement (c_parser *parser, vec<tree> *chain)
+c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
{
tree block;
location_t loc;
tree cond;
- bool first_if = false;
+ bool nested_if = false;
tree first_body, second_body;
bool in_if_block;
tree if_stmt;
@@ -5439,7 +5460,7 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
}
in_if_block = parser->in_if_block;
parser->in_if_block = true;
- first_body = c_parser_if_body (parser, &first_if, if_tinfo);
+ first_body = c_parser_if_body (parser, &nested_if, if_tinfo);
parser->in_if_block = in_if_block;
if (warn_duplicated_cond)
@@ -5470,10 +5491,22 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
}
}
second_body = c_parser_else_body (parser, else_tinfo, chain);
+ /* Set IF_P to true to indicate that this if statement has an
+ else clause. This may trigger the Wparentheses warning
+ below when we get back up to the parent if statement. */
+ if (if_p != NULL)
+ *if_p = true;
}
else
{
second_body = NULL_TREE;
+
+ /* Diagnose an ambiguous else if if-then-else is nested inside
+ if-then. */
+ if (nested_if)
+ warning_at (loc, OPT_Wparentheses,
+ "suggest explicit braces to avoid ambiguous %<else%>");
+
if (warn_duplicated_cond)
{
/* This if statement does not have an else clause. We don't
@@ -5482,7 +5515,7 @@ c_parser_if_statement (c_parser *parser, vec<tree> *chain)
chain = NULL;
}
}
- c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
+ c_finish_if_stmt (loc, cond, first_body, second_body);
if_stmt = c_end_compound_stmt (loc, block, flag_isoc99);
/* If the if statement contains array notations, then we expand them. */
@@ -5533,7 +5566,7 @@ c_parser_switch_statement (c_parser *parser)
c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
save_break = c_break_label;
c_break_label = NULL_TREE;
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, NULL/*if??*/);
c_finish_case (body, ce.original_type);
if (c_break_label)
{
@@ -5550,10 +5583,13 @@ c_parser_switch_statement (c_parser *parser)
while-statement:
while (expression) statement
-*/
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static void
-c_parser_while_statement (c_parser *parser, bool ivdep)
+c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p)
{
tree block, cond, body, save_break, save_cont;
location_t loc;
@@ -5580,7 +5616,7 @@ c_parser_while_statement (c_parser *parser, bool ivdep)
token_indent_info body_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, if_p);
c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
@@ -5615,7 +5651,7 @@ c_parser_do_statement (c_parser *parser, bool ivdep)
c_break_label = NULL_TREE;
save_cont = c_cont_label;
c_cont_label = NULL_TREE;
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, NULL);
c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
new_break = c_break_label;
c_break_label = save_break;
@@ -5690,10 +5726,13 @@ c_parser_do_statement (c_parser *parser, bool ivdep)
like the beginning of the for-statement, and we can tell it is a
foreach-statement only because the initial declaration or
expression is terminated by 'in' instead of ';'.
-*/
+
+ IF_P is used to track whether there's a (possibly labeled) if statement
+ which is not enclosed in braces and has an else clause. This is used to
+ implement -Wparentheses. */
static void
-c_parser_for_statement (c_parser *parser, bool ivdep)
+c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p)
{
tree block, cond, incr, save_break, save_cont, body;
/* The following are only used when parsing an ObjC foreach statement. */
@@ -5869,7 +5908,7 @@ c_parser_for_statement (c_parser *parser, bool ivdep)
token_indent_info body_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
- body = c_parser_c99_block_statement (parser);
+ body = c_parser_c99_block_statement (parser, if_p);
if (is_foreach_statement)
objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
@@ -10118,9 +10157,9 @@ c_parser_pragma (c_parser *parser, enum pragma_context context)
return false;
}
if (c_parser_next_token_is_keyword (parser, RID_FOR))
- c_parser_for_statement (parser, true);
+ c_parser_for_statement (parser, true, NULL);
else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
- c_parser_while_statement (parser, true);
+ c_parser_while_statement (parser, true, NULL);
else
c_parser_do_statement (parser, true);
return false;
@@ -13441,7 +13480,7 @@ static tree
c_parser_omp_structured_block (c_parser *parser)
{
tree stmt = push_stmt_list ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
return pop_stmt_list (stmt);
}
@@ -14843,7 +14882,7 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
add_stmt (c_end_compound_stmt (here, stmt, true));
}
else
- add_stmt (c_parser_c99_block_statement (parser));
+ add_stmt (c_parser_c99_block_statement (parser, NULL));
if (c_cont_label)
{
tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
@@ -15397,7 +15436,7 @@ c_parser_omp_parallel (location_t loc, c_parser *parser,
}
block = c_begin_omp_parallel ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
stmt = c_finish_omp_parallel (loc, clauses, block);
return stmt;
@@ -15458,7 +15497,7 @@ c_parser_omp_task (location_t loc, c_parser *parser)
"#pragma omp task");
block = c_begin_omp_task ();
- c_parser_statement (parser);
+ c_parser_statement (parser, NULL);
return c_finish_omp_task (loc, clauses, block);
}
diff --git gcc/c/c-tree.h gcc/c/c-tree.h
index 96ab049..d559207 100644
--- gcc/c/c-tree.h
+++ gcc/c/c-tree.h
@@ -641,7 +641,7 @@ extern tree build_asm_stmt (tree, tree);
extern int c_types_compatible_p (tree, tree);
extern tree c_begin_compound_stmt (bool);
extern tree c_end_compound_stmt (location_t, tree, bool);
-extern void c_finish_if_stmt (location_t, tree, tree, tree, bool);
+extern void c_finish_if_stmt (location_t, tree, tree, tree);
extern void c_finish_loop (location_t, tree, tree, tree, tree, tree, bool);
extern tree c_begin_stmt_expr (void);
extern tree c_finish_stmt_expr (location_t, tree);
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index fb274d5..9a14994 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -9974,12 +9974,11 @@ c_finish_case (tree body, tree type)
\f
/* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
- may be null. NESTED_IF is true if THEN_BLOCK contains another IF
- statement, and was not surrounded with parenthesis. */
+ may be null. */
void
c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
- tree else_block, bool nested_if)
+ tree else_block)
{
tree stmt;
@@ -10011,39 +10010,6 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
return;
}
}
- /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */
- if (warn_parentheses && nested_if && else_block == NULL)
- {
- tree inner_if = then_block;
-
- /* We know from the grammar productions that there is an IF nested
- within THEN_BLOCK. Due to labels and c99 conditional declarations,
- it might not be exactly THEN_BLOCK, but should be the last
- non-container statement within. */
- while (1)
- switch (TREE_CODE (inner_if))
- {
- case COND_EXPR:
- goto found;
- case BIND_EXPR:
- inner_if = BIND_EXPR_BODY (inner_if);
- break;
- case STATEMENT_LIST:
- inner_if = expr_last (then_block);
- break;
- case TRY_FINALLY_EXPR:
- case TRY_CATCH_EXPR:
- inner_if = TREE_OPERAND (inner_if, 0);
- break;
- default:
- gcc_unreachable ();
- }
- found:
-
- if (COND_EXPR_ELSE (inner_if))
- warning_at (if_locus, OPT_Wparentheses,
- "suggest explicit braces to avoid ambiguous %<else%>");
- }
stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
SET_EXPR_LOCATION (stmt, if_locus);
diff --git gcc/testsuite/gcc.dg/Wparentheses-12.c gcc/testsuite/gcc.dg/Wparentheses-12.c
index e69de29..7832415 100644
--- gcc/testsuite/gcc.dg/Wparentheses-12.c
+++ gcc/testsuite/gcc.dg/Wparentheses-12.c
@@ -0,0 +1,135 @@
+/* PR c/70436 */
+/* { dg-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+foo (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ if (b)
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ while (1)
+ if (a)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (;;)
+ if (b)
+ while (1)
+ {
+ if (a) { bar (); } else { baz (); }
+ }
+ else
+ bar ();
+
+ if (a)
+ for (;;)
+ if (b)
+ bar ();
+ else
+ baz ();
+ else bar ();
+
+ if (a)
+ while (1)
+ if (b)
+ bar ();
+ else
+ baz ();
+ else bar ();
+
+ if (a)
+ for (;;)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ for (;;)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ do
+ if (b) bar (); else baz ();
+ while (b);
+
+ if (a)
+ do
+ if (b) bar ();
+ while (b);
+ else baz ();
+}
diff --git gcc/testsuite/gcc.dg/Wparentheses-13.c gcc/testsuite/gcc.dg/Wparentheses-13.c
index e69de29..9837ba5 100644
--- gcc/testsuite/gcc.dg/Wparentheses-13.c
+++ gcc/testsuite/gcc.dg/Wparentheses-13.c
@@ -0,0 +1,67 @@
+/* PR c/70436 */
+/* { dg-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (int);
+
+void
+foo (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ if (b)
+ {
+ if (c)
+ bar (0);
+ }
+ else
+ bar (1);
+
+ if (a > 0)
+ if (a > 1)
+ if (a > 2)
+ if (a > 3)
+ if (a > 4)
+ if (a > 5) /* { dg-warning "ambiguous" } */
+ if (a > 6)
+ while (1)
+ bar (0);
+ else
+ bar (1);
+
+ if (a) /* { dg-warning "ambiguous" } */
+ if (b)
+ switch (c);
+ else
+ bar (1);
+
+ switch (a)
+ {
+ default:
+ if (b) /* { dg-warning "ambiguous" } */
+ if (c)
+ for (;;)
+ bar (0);
+ else
+ bar (1);
+ }
+
+ if (a) /* { dg-warning "ambiguous" } */
+ if (a)
+ {
+ bar (2);
+ }
+ else
+ bar (3);
+
+ if (a)
+ do if (b) bar (4); while (1);
+ else bar (5);
+
+ do
+ {
+ if (a)
+ if (b) /* { dg-warning "ambiguous" } */
+ if (c) for (;;) bar (6);
+ else bar (7);
+ } while (0);
+}
Marek
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: C PATCH to overhaul warning about dangling else (PR c/70436)
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
` (3 preceding siblings ...)
2016-04-13 15:10 ` Jakub Jelinek
@ 2016-04-15 13:07 ` Jakub Jelinek
4 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2016-04-15 13:07 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph Myers
On Wed, Apr 13, 2016 at 04:14:03PM +0200, Marek Polacek wrote:
> I revamped the warning so that it follows what the C++ FE does (i.e. passing
> IF_P bools here and there) and it seems to work quite well. I didn't mean to
> tackle the OMP bits but I bet it would be just a matter of passing IF_P
> somewhere.
Here are the promissed OpenMP, OpenACC, Cilk+ and #pragma GCC ivdep bits.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
2016-04-15 Jakub Jelinek <jakub@redhat.com>
PR c/70436
c/
* c-parser.c (c_parser_pragma): Add IF_P argument, pass it down
where needed.
(c_parser_external_declaration, c_parser_struct_or_union_specifier,
c_parser_parameter_declaration, c_parser_compound_statement_nostart,
c_parser_objc_class_instance_variables, c_parser_objc_methodprotolist):
Adjust c_parser_pragma callers.
(c_parser_statement_after_labels): Likewise. Adjust c_parser_cilk_for
caller.
(c_parser_omp_structured_block): Add IF_P argument, pass it down to
c_parser_statement.
(c_parser_oacc_data, c_parser_oacc_host_data, c_parser_oacc_loop,
c_parser_oacc_kernels_parallel, c_parser_omp_critical,
c_parser_omp_simd, c_parser_omp_for, c_parser_omp_master,
c_parser_omp_ordered, c_parser_omp_parallel, c_parser_omp_single,
c_parser_omp_task, c_parser_omp_taskgroup, c_parser_omp_distribute,
c_parser_omp_teams, c_parser_omp_target_data, c_parser_omp_target,
c_parser_omp_taskloop, c_parser_omp_construct, c_parser_cilk_grainsize,
c_parser_cilk_simd, c_parser_cilk_for): Add IF_P argument, pass it
down where needed.
(c_parser_omp_for_loop): Likewise. Clear IF_P if nbraces.
(c_parser_omp_sections_scope): Adjust c_parser_omp_structured_block
calls.
cp/
* parser.c (cp_parser_pragma): Add IF_P argument, pass it down
where needed.
(cp_parser_declaration_seq_opt, cp_parser_member_specification_opt,
cp_parser_objc_interstitial_code, cp_parser_omp_declare_simd,
cp_parser_oacc_routine): Adjust cp_parser_pragma callers.
(cp_parser_statement): Likewise. Adjust cp_parser_cilk_for caller.
(cp_parser_omp_structured_block): Add IF_P argument, pass it down to
cp_parser_statement.
(cp_parser_oacc_data, cp_parser_oacc_host_data, cp_parser_oacc_loop,
cp_parser_oacc_kernels_parallel, cp_parser_omp_critical,
cp_parser_omp_simd, cp_parser_omp_for, cp_parser_omp_master,
cp_parser_omp_ordered, cp_parser_omp_parallel, cp_parser_omp_single,
cp_parser_omp_task, cp_parser_omp_taskgroup, cp_parser_omp_distribute,
cp_parser_omp_teams, cp_parser_omp_target_data, cp_parser_omp_target,
cp_parser_omp_taskloop, cp_parser_omp_construct,
cp_parser_cilk_grainsize, cp_parser_cilk_simd, cp_parser_cilk_for):
Add IF_P argument, pass it down where needed.
(cp_parser_omp_for_loop): Likewise. Clear IF_P if nbraces.
(cp_parser_omp_sections_scope): Adjust cp_parser_omp_structured_block
calls.
testsuite/
* c-c++-common/Wparentheses-1.c: New test.
* c-c++-common/gomp/Wparentheses-1.c: New test.
* c-c++-common/gomp/Wparentheses-2.c: New test.
* c-c++-common/gomp/Wparentheses-3.c: New test.
* c-c++-common/gomp/Wparentheses-4.c: New test.
* c-c++-common/cilk-plus/PS/Wparentheses-1.c: New test.
* c-c++-common/cilk-plus/CK/Wparentheses-1.c: New test.
* c-c++-common/goacc/Wparentheses-1.c: New test.
--- gcc/c/c-parser.c.jj 2016-04-13 22:35:11.000000000 +0200
+++ gcc/c/c-parser.c 2016-04-15 11:17:16.296999900 +0200
@@ -1342,12 +1342,12 @@ static vec<tree, va_gc> *c_parser_expr_l
static void c_parser_oacc_declare (c_parser *);
static void c_parser_oacc_enter_exit_data (c_parser *, bool);
static void c_parser_oacc_update (c_parser *);
-static void c_parser_omp_construct (c_parser *);
+static void c_parser_omp_construct (c_parser *, bool *);
static void c_parser_omp_threadprivate (c_parser *);
static void c_parser_omp_barrier (c_parser *);
static void c_parser_omp_flush (c_parser *);
static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
- tree, tree *);
+ tree, tree *, bool *);
static void c_parser_omp_taskwait (c_parser *);
static void c_parser_omp_taskyield (c_parser *);
static void c_parser_omp_cancel (c_parser *);
@@ -1355,11 +1355,11 @@ static void c_parser_omp_cancellation_po
enum pragma_context { pragma_external, pragma_struct, pragma_param,
pragma_stmt, pragma_compound };
-static bool c_parser_pragma (c_parser *, enum pragma_context);
-static bool c_parser_omp_target (c_parser *, enum pragma_context);
+static bool c_parser_pragma (c_parser *, enum pragma_context, bool *);
+static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
static void c_parser_omp_end_declare_target (c_parser *);
static void c_parser_omp_declare (c_parser *, enum pragma_context);
-static bool c_parser_omp_ordered (c_parser *, enum pragma_context);
+static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
static void c_parser_oacc_routine (c_parser *parser, enum pragma_context);
/* These Objective-C parser functions are only ever called when
@@ -1390,12 +1390,12 @@ static bool c_parser_objc_diagnose_bad_e
(c_parser *, struct c_declspecs *);
/* Cilk Plus supporting routines. */
-static void c_parser_cilk_simd (c_parser *);
-static void c_parser_cilk_for (c_parser *, tree);
+static void c_parser_cilk_simd (c_parser *, bool *);
+static void c_parser_cilk_for (c_parser *, tree, bool *);
static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
-static void c_parser_cilk_grainsize (c_parser *);
+static void c_parser_cilk_grainsize (c_parser *, bool *);
/* Parse a translation unit (C90 6.7, C99 6.9).
@@ -1527,7 +1527,7 @@ c_parser_external_declaration (c_parser
break;
case CPP_PRAGMA:
mark_valid_location_for_stdc_pragma (true);
- c_parser_pragma (parser, pragma_external);
+ c_parser_pragma (parser, pragma_external, NULL);
mark_valid_location_for_stdc_pragma (false);
break;
case CPP_PLUS:
@@ -2927,7 +2927,7 @@ c_parser_struct_or_union_specifier (c_pa
/* Accept #pragmas at struct scope. */
if (c_parser_next_token_is (parser, CPP_PRAGMA))
{
- c_parser_pragma (parser, pragma_struct);
+ c_parser_pragma (parser, pragma_struct, NULL);
continue;
}
/* Parse some comma-separated declarations, but not the
@@ -3796,7 +3796,7 @@ c_parser_parameter_declaration (c_parser
/* Accept #pragmas between parameter declarations. */
while (c_parser_next_token_is (parser, CPP_PRAGMA))
- c_parser_pragma (parser, pragma_param);
+ c_parser_pragma (parser, pragma_param, NULL);
if (!c_parser_next_token_starts_declspecs (parser))
{
@@ -4824,7 +4824,8 @@ c_parser_compound_statement_nostart (c_p
places that would turn into syntax errors if the directive
were ignored. */
if (c_parser_pragma (parser,
- last_label ? pragma_stmt : pragma_compound))
+ last_label ? pragma_stmt : pragma_compound,
+ NULL))
last_label = false, last_stmt = true;
}
else if (c_parser_next_token_is (parser, CPP_EOF))
@@ -5156,7 +5157,7 @@ c_parser_statement_after_labels (c_parse
c_parser_skip_to_end_of_block_or_statement (parser);
}
else
- c_parser_cilk_for (parser, integer_zero_node);
+ c_parser_cilk_for (parser, integer_zero_node, if_p);
break;
case RID_CILK_SYNC:
c_parser_consume_token (parser);
@@ -5276,7 +5277,7 @@ c_parser_statement_after_labels (c_parse
c_parser_consume_token (parser);
break;
case CPP_PRAGMA:
- c_parser_pragma (parser, pragma_stmt);
+ c_parser_pragma (parser, pragma_stmt, if_p);
break;
default:
expr_stmt:
@@ -8787,7 +8788,7 @@ c_parser_objc_class_instance_variables (
}
else if (c_parser_next_token_is (parser, CPP_PRAGMA))
{
- c_parser_pragma (parser, pragma_external);
+ c_parser_pragma (parser, pragma_external, NULL);
continue;
}
@@ -9058,7 +9059,7 @@ c_parser_objc_methodprotolist (c_parser
c_parser_objc_methodproto (parser);
break;
case CPP_PRAGMA:
- c_parser_pragma (parser, pragma_external);
+ c_parser_pragma (parser, pragma_external, NULL);
break;
case CPP_EOF:
return;
@@ -10019,7 +10020,7 @@ c_parser_objc_at_dynamic_declaration (c_
true if we actually parsed such a pragma. */
static bool
-c_parser_pragma (c_parser *parser, enum pragma_context context)
+c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p)
{
unsigned int id;
@@ -10126,7 +10127,7 @@ c_parser_pragma (c_parser *parser, enum
return false;
case PRAGMA_OMP_TARGET:
- return c_parser_omp_target (parser, context);
+ return c_parser_omp_target (parser, context, if_p);
case PRAGMA_OMP_END_DECLARE_TARGET:
c_parser_omp_end_declare_target (parser);
@@ -10144,7 +10145,7 @@ c_parser_pragma (c_parser *parser, enum
return false;
case PRAGMA_OMP_ORDERED:
- return c_parser_omp_ordered (parser, context);
+ return c_parser_omp_ordered (parser, context, if_p);
case PRAGMA_IVDEP:
c_parser_consume_pragma (parser);
@@ -10157,9 +10158,9 @@ c_parser_pragma (c_parser *parser, enum
return false;
}
if (c_parser_next_token_is_keyword (parser, RID_FOR))
- c_parser_for_statement (parser, true, NULL);
+ c_parser_for_statement (parser, true, if_p);
else if (c_parser_next_token_is_keyword (parser, RID_WHILE))
- c_parser_while_statement (parser, true, NULL);
+ c_parser_while_statement (parser, true, if_p);
else
c_parser_do_statement (parser, true);
return false;
@@ -10173,7 +10174,7 @@ c_parser_pragma (c_parser *parser, enum
if (!c_parser_cilk_verify_simd (parser, context))
return false;
c_parser_consume_pragma (parser);
- c_parser_cilk_simd (parser);
+ c_parser_cilk_simd (parser, if_p);
return false;
case PRAGMA_CILK_GRAINSIZE:
if (!flag_cilkplus)
@@ -10190,7 +10191,7 @@ c_parser_pragma (c_parser *parser, enum
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
return false;
}
- c_parser_cilk_grainsize (parser);
+ c_parser_cilk_grainsize (parser, if_p);
return false;
default:
@@ -10203,7 +10204,7 @@ c_parser_pragma (c_parser *parser, enum
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
return false;
}
- c_parser_omp_construct (parser);
+ c_parser_omp_construct (parser, if_p);
return true;
}
break;
@@ -13477,10 +13478,10 @@ c_parser_omp_all_clauses (c_parser *pars
c_parser_statement calls add_stmt. */
static tree
-c_parser_omp_structured_block (c_parser *parser)
+c_parser_omp_structured_block (c_parser *parser, bool *if_p)
{
tree stmt = push_stmt_list ();
- c_parser_statement (parser, NULL);
+ c_parser_statement (parser, if_p);
return pop_stmt_list (stmt);
}
@@ -13530,7 +13531,7 @@ c_parser_oacc_cache (location_t loc, c_p
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
static tree
-c_parser_oacc_data (location_t loc, c_parser *parser)
+c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p)
{
tree stmt, clauses, block;
@@ -13538,7 +13539,7 @@ c_parser_oacc_data (location_t loc, c_pa
"#pragma acc data");
block = c_begin_omp_parallel ();
- add_stmt (c_parser_omp_structured_block (parser));
+ add_stmt (c_parser_omp_structured_block (parser, if_p));
stmt = c_finish_oacc_data (loc, clauses, block);
@@ -13784,7 +13785,7 @@ c_parser_oacc_enter_exit_data (c_parser
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
static tree
-c_parser_oacc_host_data (location_t loc, c_parser *parser)
+c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p)
{
tree stmt, clauses, block;
@@ -13792,7 +13793,7 @@ c_parser_oacc_host_data (location_t loc,
"#pragma acc host_data");
block = c_begin_omp_parallel ();
- add_stmt (c_parser_omp_structured_block (parser));
+ add_stmt (c_parser_omp_structured_block (parser, if_p));
stmt = c_finish_oacc_host_data (loc, clauses, block);
return stmt;
}
@@ -13819,7 +13820,7 @@ c_parser_oacc_host_data (location_t loc,
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
static tree
c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
- omp_clause_mask mask, tree *cclauses)
+ omp_clause_mask mask, tree *cclauses, bool *if_p)
{
strcat (p_name, " loop");
mask |= OACC_LOOP_CLAUSE_MASK;
@@ -13836,7 +13837,8 @@ c_parser_oacc_loop (location_t loc, c_pa
}
tree block = c_begin_compound_stmt (true);
- tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL);
+ tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL,
+ if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
@@ -13895,7 +13897,8 @@ c_parser_oacc_loop (location_t loc, c_pa
static tree
c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser,
- enum pragma_kind p_kind, char *p_name)
+ enum pragma_kind p_kind, char *p_name,
+ bool *if_p)
{
omp_clause_mask mask;
enum tree_code code;
@@ -13925,7 +13928,7 @@ c_parser_oacc_kernels_parallel (location
tree block = c_begin_omp_parallel ();
tree clauses;
- c_parser_oacc_loop (loc, parser, p_name, mask, &clauses);
+ c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p);
return c_finish_omp_construct (loc, code, block, clauses);
}
}
@@ -13933,7 +13936,7 @@ c_parser_oacc_kernels_parallel (location
tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
tree block = c_begin_omp_parallel ();
- add_stmt (c_parser_omp_structured_block (parser));
+ add_stmt (c_parser_omp_structured_block (parser, if_p));
return c_finish_omp_construct (loc, code, block, clauses);
}
@@ -14576,7 +14579,7 @@ c_parser_omp_barrier (c_parser *parser)
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
static tree
-c_parser_omp_critical (location_t loc, c_parser *parser)
+c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p)
{
tree stmt, name = NULL_TREE, clauses = NULL_TREE;
@@ -14603,7 +14606,7 @@ c_parser_omp_critical (location_t loc, c
c_parser_skip_to_pragma_eol (parser);
}
- stmt = c_parser_omp_structured_block (parser);
+ stmt = c_parser_omp_structured_block (parser, if_p);
return c_finish_omp_critical (loc, stmt, name, clauses);
}
@@ -14635,7 +14638,7 @@ c_parser_omp_flush (c_parser *parser)
static tree
c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
- tree clauses, tree *cclauses)
+ tree clauses, tree *cclauses, bool *if_p)
{
tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
tree declv, condv, incrv, initv, ret = NULL_TREE;
@@ -14865,6 +14868,9 @@ c_parser_omp_for_loop (location_t loc, c
nbraces += bracecount;
}
+ if (nbraces)
+ if_p = NULL;
+
save_break = c_break_label;
if (code == CILK_SIMD)
c_break_label = build_int_cst (size_type_node, 2);
@@ -14882,7 +14888,7 @@ c_parser_omp_for_loop (location_t loc, c
add_stmt (c_end_compound_stmt (here, stmt, true));
}
else
- add_stmt (c_parser_c99_block_statement (parser, NULL));
+ add_stmt (c_parser_c99_block_statement (parser, if_p));
if (c_cont_label)
{
tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
@@ -15025,7 +15031,8 @@ omp_split_clauses (location_t loc, enum
static tree
c_parser_omp_simd (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree block, clauses, ret;
@@ -15049,7 +15056,7 @@ c_parser_omp_simd (location_t loc, c_par
}
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses);
+ ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
@@ -15080,7 +15087,8 @@ c_parser_omp_simd (location_t loc, c_par
static tree
c_parser_omp_for (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree block, clauses, ret;
@@ -15104,9 +15112,10 @@ c_parser_omp_for (location_t loc, c_pars
c_parser_consume_token (parser);
if (!flag_openmp) /* flag_openmp_simd */
- return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
+ if_p);
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
block = c_end_compound_stmt (loc, block, true);
if (ret == NULL_TREE)
return ret;
@@ -15137,7 +15146,7 @@ c_parser_omp_for (location_t loc, c_pars
}
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses);
+ ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
@@ -15152,10 +15161,11 @@ c_parser_omp_for (location_t loc, c_pars
*/
static tree
-c_parser_omp_master (location_t loc, c_parser *parser)
+c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p)
{
c_parser_skip_to_pragma_eol (parser);
- return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
+ return c_finish_omp_master (loc, c_parser_omp_structured_block (parser,
+ if_p));
}
/* OpenMP 2.5:
@@ -15176,7 +15186,8 @@ c_parser_omp_master (location_t loc, c_p
(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
static bool
-c_parser_omp_ordered (c_parser *parser, enum pragma_context context)
+c_parser_omp_ordered (c_parser *parser, enum pragma_context context,
+ bool *if_p)
{
location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_pragma (parser);
@@ -15215,7 +15226,7 @@ c_parser_omp_ordered (c_parser *parser,
tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
"#pragma omp ordered");
c_finish_omp_ordered (loc, clauses,
- c_parser_omp_structured_block (parser));
+ c_parser_omp_structured_block (parser, if_p));
return true;
}
@@ -15249,7 +15260,7 @@ c_parser_omp_sections_scope (location_t
if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
{
- substmt = c_parser_omp_structured_block (parser);
+ substmt = c_parser_omp_structured_block (parser, NULL);
substmt = build1 (OMP_SECTION, void_type_node, substmt);
SET_EXPR_LOCATION (substmt, loc);
add_stmt (substmt);
@@ -15275,7 +15286,7 @@ c_parser_omp_sections_scope (location_t
error_suppress = true;
}
- substmt = c_parser_omp_structured_block (parser);
+ substmt = c_parser_omp_structured_block (parser, NULL);
substmt = build1 (OMP_SECTION, void_type_node, substmt);
SET_EXPR_LOCATION (substmt, loc);
add_stmt (substmt);
@@ -15363,7 +15374,8 @@ c_parser_omp_sections (location_t loc, c
static tree
c_parser_omp_parallel (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree stmt, clauses, block;
@@ -15382,9 +15394,9 @@ c_parser_omp_parallel (location_t loc, c
c_parser_consume_token (parser);
if (!flag_openmp) /* flag_openmp_simd */
- return c_parser_omp_for (loc, parser, p_name, mask, cclauses);
+ return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
block = c_begin_omp_parallel ();
- tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses);
+ tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p);
stmt
= c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
block);
@@ -15436,7 +15448,7 @@ c_parser_omp_parallel (location_t loc, c
}
block = c_begin_omp_parallel ();
- c_parser_statement (parser, NULL);
+ c_parser_statement (parser, if_p);
stmt = c_finish_omp_parallel (loc, clauses, block);
return stmt;
@@ -15456,7 +15468,7 @@ c_parser_omp_parallel (location_t loc, c
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
static tree
-c_parser_omp_single (location_t loc, c_parser *parser)
+c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p)
{
tree stmt = make_node (OMP_SINGLE);
SET_EXPR_LOCATION (stmt, loc);
@@ -15465,7 +15477,7 @@ c_parser_omp_single (location_t loc, c_p
OMP_SINGLE_CLAUSES (stmt)
= c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
"#pragma omp single");
- OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
+ OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
return add_stmt (stmt);
}
@@ -15489,7 +15501,7 @@ c_parser_omp_single (location_t loc, c_p
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
static tree
-c_parser_omp_task (location_t loc, c_parser *parser)
+c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p)
{
tree clauses, block;
@@ -15497,7 +15509,7 @@ c_parser_omp_task (location_t loc, c_par
"#pragma omp task");
block = c_begin_omp_task ();
- c_parser_statement (parser, NULL);
+ c_parser_statement (parser, if_p);
return c_finish_omp_task (loc, clauses, block);
}
@@ -15534,11 +15546,12 @@ c_parser_omp_taskyield (c_parser *parser
*/
static tree
-c_parser_omp_taskgroup (c_parser *parser)
+c_parser_omp_taskgroup (c_parser *parser, bool *if_p)
{
location_t loc = c_parser_peek_token (parser)->location;
c_parser_skip_to_pragma_eol (parser);
- return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser));
+ return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser,
+ if_p));
}
/* OpenMP 4.0:
@@ -15622,7 +15635,8 @@ c_parser_omp_cancellation_point (c_parse
static tree
c_parser_omp_distribute (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, block, ret;
@@ -15648,16 +15662,19 @@ c_parser_omp_distribute (location_t loc,
if (!flag_openmp) /* flag_openmp_simd */
{
if (simd)
- return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
+ if_p);
else
return c_parser_omp_parallel (loc, parser, p_name, mask,
- cclauses);
+ cclauses, if_p);
}
block = c_begin_compound_stmt (true);
if (simd)
- ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
+ if_p);
else
- ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses);
+ ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses,
+ if_p);
block = c_end_compound_stmt (loc, block, true);
if (ret == NULL)
return ret;
@@ -15684,7 +15701,8 @@ c_parser_omp_distribute (location_t loc,
}
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL);
+ ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL,
+ if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
@@ -15706,7 +15724,8 @@ c_parser_omp_distribute (location_t loc,
static tree
c_parser_omp_teams (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, block, ret;
@@ -15724,9 +15743,11 @@ c_parser_omp_teams (location_t loc, c_pa
c_parser_consume_token (parser);
if (!flag_openmp) /* flag_openmp_simd */
- return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
+ return c_parser_omp_distribute (loc, parser, p_name, mask,
+ cclauses, if_p);
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses);
+ ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses,
+ if_p);
block = c_end_compound_stmt (loc, block, true);
if (ret == NULL)
return ret;
@@ -15755,7 +15776,7 @@ c_parser_omp_teams (location_t loc, c_pa
tree stmt = make_node (OMP_TEAMS);
TREE_TYPE (stmt) = void_type_node;
OMP_TEAMS_CLAUSES (stmt) = clauses;
- OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser);
+ OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p);
return add_stmt (stmt);
}
@@ -15771,7 +15792,7 @@ c_parser_omp_teams (location_t loc, c_pa
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
static tree
-c_parser_omp_target_data (location_t loc, c_parser *parser)
+c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p)
{
tree clauses
= c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
@@ -15820,7 +15841,7 @@ c_parser_omp_target_data (location_t loc
OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
keep_next_level ();
tree block = c_begin_compound_stmt (true);
- add_stmt (c_parser_omp_structured_block (parser));
+ add_stmt (c_parser_omp_structured_block (parser, if_p));
OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true);
SET_EXPR_LOCATION (stmt, loc);
@@ -16060,7 +16081,7 @@ c_parser_omp_target_exit_data (location_
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
static bool
-c_parser_omp_target (c_parser *parser, enum pragma_context context)
+c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p)
{
location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_pragma (parser);
@@ -16100,17 +16121,17 @@ c_parser_omp_target (c_parser *parser, e
case OMP_TEAMS:
stmt = c_parser_omp_teams (loc, parser, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
case OMP_PARALLEL:
stmt = c_parser_omp_parallel (loc, parser, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
case OMP_SIMD:
stmt = c_parser_omp_simd (loc, parser, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
default:
gcc_unreachable ();
@@ -16123,15 +16144,18 @@ c_parser_omp_target (c_parser *parser, e
{
case OMP_TEAMS:
ret = c_parser_omp_teams (loc, parser, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
case OMP_PARALLEL:
ret = c_parser_omp_parallel (loc, parser, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
case OMP_SIMD:
ret = c_parser_omp_simd (loc, parser, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
default:
gcc_unreachable ();
@@ -16182,7 +16206,7 @@ c_parser_omp_target (c_parser *parser, e
else if (strcmp (p, "data") == 0)
{
c_parser_consume_token (parser);
- c_parser_omp_target_data (loc, parser);
+ c_parser_omp_target_data (loc, parser, if_p);
return true;
}
else if (strcmp (p, "enter") == 0)
@@ -16213,7 +16237,7 @@ c_parser_omp_target (c_parser *parser, e
pc = &OMP_TARGET_CLAUSES (stmt);
keep_next_level ();
block = c_begin_compound_stmt (true);
- add_stmt (c_parser_omp_structured_block (parser));
+ add_stmt (c_parser_omp_structured_block (parser, if_p));
OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true);
SET_EXPR_LOCATION (stmt, loc);
@@ -17022,7 +17046,8 @@ c_parser_omp_declare (c_parser *parser,
static tree
c_parser_omp_taskloop (location_t loc, c_parser *parser,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, block, ret;
@@ -17041,9 +17066,10 @@ c_parser_omp_taskloop (location_t loc, c
mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION);
c_parser_consume_token (parser);
if (!flag_openmp) /* flag_openmp_simd */
- return c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ return c_parser_omp_simd (loc, parser, p_name, mask, cclauses,
+ if_p);
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses);
+ ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p);
block = c_end_compound_stmt (loc, block, true);
if (ret == NULL)
return ret;
@@ -17070,7 +17096,7 @@ c_parser_omp_taskloop (location_t loc, c
}
block = c_begin_compound_stmt (true);
- ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL);
+ ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
@@ -17080,7 +17106,7 @@ c_parser_omp_taskloop (location_t loc, c
/* Main entry point to parsing most OpenMP pragmas. */
static void
-c_parser_omp_construct (c_parser *parser)
+c_parser_omp_construct (c_parser *parser, bool *if_p)
{
enum pragma_kind p_kind;
location_t loc;
@@ -17102,19 +17128,20 @@ c_parser_omp_construct (c_parser *parser
stmt = c_parser_oacc_cache (loc, parser);
break;
case PRAGMA_OACC_DATA:
- stmt = c_parser_oacc_data (loc, parser);
+ stmt = c_parser_oacc_data (loc, parser, if_p);
break;
case PRAGMA_OACC_HOST_DATA:
- stmt = c_parser_oacc_host_data (loc, parser);
+ stmt = c_parser_oacc_host_data (loc, parser, if_p);
break;
case PRAGMA_OACC_KERNELS:
case PRAGMA_OACC_PARALLEL:
strcpy (p_name, "#pragma acc");
- stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name);
+ stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name,
+ if_p);
break;
case PRAGMA_OACC_LOOP:
strcpy (p_name, "#pragma acc");
- stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OACC_WAIT:
strcpy (p_name, "#pragma wait");
@@ -17124,22 +17151,22 @@ c_parser_omp_construct (c_parser *parser
c_parser_omp_atomic (loc, parser);
return;
case PRAGMA_OMP_CRITICAL:
- stmt = c_parser_omp_critical (loc, parser);
+ stmt = c_parser_omp_critical (loc, parser, if_p);
break;
case PRAGMA_OMP_DISTRIBUTE:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OMP_FOR:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OMP_MASTER:
- stmt = c_parser_omp_master (loc, parser);
+ stmt = c_parser_omp_master (loc, parser, if_p);
break;
case PRAGMA_OMP_PARALLEL:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OMP_SECTIONS:
strcpy (p_name, "#pragma omp");
@@ -17147,24 +17174,24 @@ c_parser_omp_construct (c_parser *parser
break;
case PRAGMA_OMP_SIMD:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OMP_SINGLE:
- stmt = c_parser_omp_single (loc, parser);
+ stmt = c_parser_omp_single (loc, parser, if_p);
break;
case PRAGMA_OMP_TASK:
- stmt = c_parser_omp_task (loc, parser);
+ stmt = c_parser_omp_task (loc, parser, if_p);
break;
case PRAGMA_OMP_TASKGROUP:
- stmt = c_parser_omp_taskgroup (parser);
+ stmt = c_parser_omp_taskgroup (parser, if_p);
break;
case PRAGMA_OMP_TASKLOOP:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p);
break;
case PRAGMA_OMP_TEAMS:
strcpy (p_name, "#pragma omp");
- stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL);
+ stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p);
break;
default:
gcc_unreachable ();
@@ -17491,7 +17518,7 @@ c_parser_cilk_all_clauses (c_parser *par
*/
static void
-c_parser_cilk_grainsize (c_parser *parser)
+c_parser_cilk_grainsize (c_parser *parser, bool *if_p)
{
extern tree convert_to_integer (tree, tree);
@@ -17516,7 +17543,7 @@ c_parser_cilk_grainsize (c_parser *parse
{
if (grain == NULL_TREE || grain == error_mark_node)
grain = integer_zero_node;
- c_parser_cilk_for (parser, grain);
+ c_parser_cilk_for (parser, grain, if_p);
}
else
warning (0, "%<#pragma cilk grainsize%> is not followed by "
@@ -17529,12 +17556,12 @@ c_parser_cilk_grainsize (c_parser *parse
/* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
static void
-c_parser_cilk_simd (c_parser *parser)
+c_parser_cilk_simd (c_parser *parser, bool *if_p)
{
tree clauses = c_parser_cilk_all_clauses (parser);
tree block = c_begin_compound_stmt (true);
location_t loc = c_parser_peek_token (parser)->location;
- c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL);
+ c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL, if_p);
block = c_end_compound_stmt (loc, block, true);
add_stmt (block);
}
@@ -17559,7 +17586,7 @@ c_get_temp_regvar (tree type, tree init)
GRAIN is the grain value passed in through pragma or 0. */
static void
-c_parser_cilk_for (c_parser *parser, tree grain)
+c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p)
{
tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE);
OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR;
@@ -17569,7 +17596,8 @@ c_parser_cilk_for (c_parser *parser, tre
tree block = c_begin_compound_stmt (true);
tree sb = push_stmt_list ();
location_t loc = c_parser_peek_token (parser)->location;
- tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL);
+ tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL,
+ if_p);
sb = pop_stmt_list (sb);
if (omp_for)
--- gcc/cp/parser.c.jj 2016-04-12 21:31:06.000000000 +0200
+++ gcc/cp/parser.c 2016-04-15 08:33:44.088177350 +0200
@@ -249,9 +249,9 @@ static tree cp_literal_operator_id
(const char *);
static void cp_parser_cilk_simd
- (cp_parser *, cp_token *);
+ (cp_parser *, cp_token *, bool *);
static tree cp_parser_cilk_for
- (cp_parser *, tree);
+ (cp_parser *, tree, bool *);
static bool cp_parser_omp_declare_reduction_exprs
(tree, cp_parser *);
static tree cp_parser_cilk_simd_vectorlength
@@ -2434,7 +2434,7 @@ enum pragma_context {
pragma_compound
};
static bool cp_parser_pragma
- (cp_parser *, enum pragma_context);
+ (cp_parser *, enum pragma_context, bool *);
/* Objective-C++ Productions */
@@ -10404,7 +10404,7 @@ cp_parser_statement (cp_parser* parser,
statement = error_mark_node;
}
else
- statement = cp_parser_cilk_for (parser, integer_zero_node);
+ statement = cp_parser_cilk_for (parser, integer_zero_node, if_p);
break;
case RID_BREAK:
@@ -10496,8 +10496,8 @@ cp_parser_statement (cp_parser* parser,
return so that we can check for a close brace. Otherwise we
require a real statement and must go back and read one. */
if (in_compound)
- cp_parser_pragma (parser, pragma_compound);
- else if (!cp_parser_pragma (parser, pragma_stmt))
+ cp_parser_pragma (parser, pragma_compound, if_p);
+ else if (!cp_parser_pragma (parser, pragma_stmt, if_p))
goto restart;
return;
}
@@ -12016,7 +12016,7 @@ cp_parser_declaration_seq_opt (cp_parser
A nested declaration cannot, so this is done here and not
in cp_parser_declaration. (A #pragma at block scope is
handled in cp_parser_statement.) */
- cp_parser_pragma (parser, pragma_external);
+ cp_parser_pragma (parser, pragma_external, NULL);
continue;
}
@@ -22113,7 +22113,7 @@ cp_parser_member_specification_opt (cp_p
/* Accept #pragmas at class scope. */
if (token->type == CPP_PRAGMA)
{
- cp_parser_pragma (parser, pragma_member);
+ cp_parser_pragma (parser, pragma_member, NULL);
break;
}
@@ -28449,7 +28449,7 @@ cp_parser_objc_interstitial_code (cp_par
cp_parser_linkage_specification (parser);
/* Handle #pragma, if any. */
else if (token->type == CPP_PRAGMA)
- cp_parser_pragma (parser, pragma_objc_icode);
+ cp_parser_pragma (parser, pragma_objc_icode, NULL);
/* Allow stray semicolons. */
else if (token->type == CPP_SEMICOLON)
cp_lexer_consume_token (parser->lexer);
@@ -32577,12 +32577,12 @@ cp_parser_end_omp_structured_block (cp_p
}
static tree
-cp_parser_omp_structured_block (cp_parser *parser)
+cp_parser_omp_structured_block (cp_parser *parser, bool *if_p)
{
tree stmt = begin_omp_structured_block ();
unsigned int save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
return finish_omp_structured_block (stmt);
@@ -33042,7 +33042,7 @@ cp_parser_omp_barrier (cp_parser *parser
( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
static tree
-cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree stmt, name = NULL_TREE, clauses = NULL_TREE;
@@ -33067,7 +33067,7 @@ cp_parser_omp_critical (cp_parser *parse
else
cp_parser_require_pragma_eol (parser, pragma_tok);
- stmt = cp_parser_omp_structured_block (parser);
+ stmt = cp_parser_omp_structured_block (parser, if_p);
return c_finish_omp_critical (input_location, stmt, name, clauses);
}
@@ -33443,7 +33443,7 @@ cp_parser_omp_for_loop_init (cp_parser *
static tree
cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses,
- tree *cclauses)
+ tree *cclauses, bool *if_p)
{
tree init, orig_init, cond, incr, body, decl, pre_body = NULL_TREE, ret;
tree real_decl, initv, condv, incrv, declv;
@@ -33702,6 +33702,9 @@ cp_parser_omp_for_loop (cp_parser *parse
}
}
+ if (nbraces)
+ if_p = NULL;
+
/* Note that we saved the original contents of this flag when we entered
the structured block, and so we don't need to re-save it here. */
if (code == CILK_SIMD || code == CILK_FOR)
@@ -33712,7 +33715,7 @@ cp_parser_omp_for_loop (cp_parser *parse
/* Note that the grammar doesn't call for a structured block here,
though the loop as a whole is a structured block. */
body = push_stmt_list ();
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
body = pop_stmt_list (body);
if (declv == NULL_TREE)
@@ -33781,7 +33784,8 @@ cp_omp_split_clauses (location_t loc, en
static tree
cp_parser_omp_simd (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, sb, ret;
unsigned int save;
@@ -33810,7 +33814,7 @@ cp_parser_omp_simd (cp_parser *parser, c
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
- ret = cp_parser_omp_for_loop (parser, OMP_SIMD, clauses, cclauses);
+ ret = cp_parser_omp_for_loop (parser, OMP_SIMD, clauses, cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
add_stmt (finish_omp_structured_block (sb));
@@ -33839,7 +33843,8 @@ cp_parser_omp_simd (cp_parser *parser, c
static tree
cp_parser_omp_for (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, sb, ret;
unsigned int save;
@@ -33867,11 +33872,11 @@ cp_parser_omp_for (cp_parser *parser, cp
cp_lexer_consume_token (parser->lexer);
if (!flag_openmp) /* flag_openmp_simd */
return cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
ret = cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
tree body = finish_omp_structured_block (sb);
if (ret == NULL)
@@ -33906,7 +33911,7 @@ cp_parser_omp_for (cp_parser *parser, cp
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
- ret = cp_parser_omp_for_loop (parser, OMP_FOR, clauses, cclauses);
+ ret = cp_parser_omp_for_loop (parser, OMP_FOR, clauses, cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
add_stmt (finish_omp_structured_block (sb));
@@ -33919,11 +33924,11 @@ cp_parser_omp_for (cp_parser *parser, cp
structured-block */
static tree
-cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
cp_parser_require_pragma_eol (parser, pragma_tok);
return c_finish_omp_master (input_location,
- cp_parser_omp_structured_block (parser));
+ cp_parser_omp_structured_block (parser, if_p));
}
/* OpenMP 2.5:
@@ -33943,7 +33948,7 @@ cp_parser_omp_master (cp_parser *parser,
static bool
cp_parser_omp_ordered (cp_parser *parser, cp_token *pragma_tok,
- enum pragma_context context)
+ enum pragma_context context, bool *if_p)
{
location_t loc = pragma_tok->location;
@@ -33982,7 +33987,7 @@ cp_parser_omp_ordered (cp_parser *parser
= cp_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK,
"#pragma omp ordered", pragma_tok);
c_finish_omp_ordered (loc, clauses,
- cp_parser_omp_structured_block (parser));
+ cp_parser_omp_structured_block (parser, if_p));
return true;
}
@@ -34010,7 +34015,7 @@ cp_parser_omp_sections_scope (cp_parser
if (cp_parser_pragma_kind (cp_lexer_peek_token (parser->lexer))
!= PRAGMA_OMP_SECTION)
{
- substmt = cp_parser_omp_structured_block (parser);
+ substmt = cp_parser_omp_structured_block (parser, NULL);
substmt = build1 (OMP_SECTION, void_type_node, substmt);
add_stmt (substmt);
}
@@ -34035,7 +34040,7 @@ cp_parser_omp_sections_scope (cp_parser
error_suppress = true;
}
- substmt = cp_parser_omp_structured_block (parser);
+ substmt = cp_parser_omp_structured_block (parser, NULL);
substmt = build1 (OMP_SECTION, void_type_node, substmt);
add_stmt (substmt);
}
@@ -34114,7 +34119,8 @@ cp_parser_omp_sections (cp_parser *parse
static tree
cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree stmt, clauses, block;
unsigned int save;
@@ -34135,10 +34141,12 @@ cp_parser_omp_parallel (cp_parser *parse
cp_lexer_consume_token (parser->lexer);
if (!flag_openmp) /* flag_openmp_simd */
- return cp_parser_omp_for (parser, pragma_tok, p_name, mask, cclauses);
+ return cp_parser_omp_for (parser, pragma_tok, p_name, mask, cclauses,
+ if_p);
block = begin_omp_parallel ();
save = cp_parser_begin_omp_structured_block (parser);
- tree ret = cp_parser_omp_for (parser, pragma_tok, p_name, mask, cclauses);
+ tree ret = cp_parser_omp_for (parser, pragma_tok, p_name, mask, cclauses,
+ if_p);
cp_parser_end_omp_structured_block (parser, save);
stmt = finish_omp_parallel (cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL],
block);
@@ -34192,7 +34200,7 @@ cp_parser_omp_parallel (cp_parser *parse
block = begin_omp_parallel ();
save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
stmt = finish_omp_parallel (clauses, block);
return stmt;
@@ -34209,7 +34217,7 @@ cp_parser_omp_parallel (cp_parser *parse
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
static tree
-cp_parser_omp_single (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_single (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree stmt = make_node (OMP_SINGLE);
TREE_TYPE (stmt) = void_type_node;
@@ -34217,7 +34225,7 @@ cp_parser_omp_single (cp_parser *parser,
OMP_SINGLE_CLAUSES (stmt)
= cp_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
"#pragma omp single", pragma_tok);
- OMP_SINGLE_BODY (stmt) = cp_parser_omp_structured_block (parser);
+ OMP_SINGLE_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p);
return add_stmt (stmt);
}
@@ -34239,7 +34247,7 @@ cp_parser_omp_single (cp_parser *parser,
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
static tree
-cp_parser_omp_task (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_task (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree clauses, block;
unsigned int save;
@@ -34248,7 +34256,7 @@ cp_parser_omp_task (cp_parser *parser, c
"#pragma omp task", pragma_tok);
block = begin_omp_task ();
save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
return finish_omp_task (clauses, block);
}
@@ -34278,11 +34286,12 @@ cp_parser_omp_taskyield (cp_parser *pars
structured-block */
static tree
-cp_parser_omp_taskgroup (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_taskgroup (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
cp_parser_require_pragma_eol (parser, pragma_tok);
return c_finish_omp_taskgroup (input_location,
- cp_parser_omp_structured_block (parser));
+ cp_parser_omp_structured_block (parser,
+ if_p));
}
@@ -34371,7 +34380,8 @@ cp_parser_omp_cancellation_point (cp_par
static tree
cp_parser_omp_distribute (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, sb, ret;
unsigned int save;
@@ -34401,19 +34411,19 @@ cp_parser_omp_distribute (cp_parser *par
{
if (simd)
return cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
else
return cp_parser_omp_parallel (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
}
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
if (simd)
ret = cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
else
ret = cp_parser_omp_parallel (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
tree body = finish_omp_structured_block (sb);
if (ret == NULL)
@@ -34444,7 +34454,7 @@ cp_parser_omp_distribute (cp_parser *par
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
- ret = cp_parser_omp_for_loop (parser, OMP_DISTRIBUTE, clauses, NULL);
+ ret = cp_parser_omp_for_loop (parser, OMP_DISTRIBUTE, clauses, NULL, if_p);
cp_parser_end_omp_structured_block (parser, save);
add_stmt (finish_omp_structured_block (sb));
@@ -34467,7 +34477,8 @@ cp_parser_omp_distribute (cp_parser *par
static tree
cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, sb, ret;
unsigned int save;
@@ -34489,11 +34500,11 @@ cp_parser_omp_teams (cp_parser *parser,
cp_lexer_consume_token (parser->lexer);
if (!flag_openmp) /* flag_openmp_simd */
return cp_parser_omp_distribute (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
ret = cp_parser_omp_distribute (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
tree body = finish_omp_structured_block (sb);
if (ret == NULL)
@@ -34524,7 +34535,7 @@ cp_parser_omp_teams (cp_parser *parser,
tree stmt = make_node (OMP_TEAMS);
TREE_TYPE (stmt) = void_type_node;
OMP_TEAMS_CLAUSES (stmt) = clauses;
- OMP_TEAMS_BODY (stmt) = cp_parser_omp_structured_block (parser);
+ OMP_TEAMS_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p);
return add_stmt (stmt);
}
@@ -34540,7 +34551,7 @@ cp_parser_omp_teams (cp_parser *parser,
| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
static tree
-cp_parser_omp_target_data (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_target_data (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree clauses
= cp_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK,
@@ -34590,7 +34601,7 @@ cp_parser_omp_target_data (cp_parser *pa
OMP_TARGET_DATA_CLAUSES (stmt) = clauses;
keep_next_level (true);
- OMP_TARGET_DATA_BODY (stmt) = cp_parser_omp_structured_block (parser);
+ OMP_TARGET_DATA_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p);
SET_EXPR_LOCATION (stmt, pragma_tok->location);
return add_stmt (stmt);
@@ -34835,7 +34846,7 @@ cp_parser_omp_target_update (cp_parser *
static bool
cp_parser_omp_target (cp_parser *parser, cp_token *pragma_tok,
- enum pragma_context context)
+ enum pragma_context context, bool *if_p)
{
tree *pc = NULL, stmt;
@@ -34874,17 +34885,17 @@ cp_parser_omp_target (cp_parser *parser,
case OMP_TEAMS:
stmt = cp_parser_omp_teams (parser, pragma_tok, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
case OMP_PARALLEL:
stmt = cp_parser_omp_parallel (parser, pragma_tok, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
case OMP_SIMD:
stmt = cp_parser_omp_simd (parser, pragma_tok, p_name,
OMP_TARGET_CLAUSE_MASK,
- cclauses);
+ cclauses, if_p);
break;
default:
gcc_unreachable ();
@@ -34898,15 +34909,18 @@ cp_parser_omp_target (cp_parser *parser,
{
case OMP_TEAMS:
ret = cp_parser_omp_teams (parser, pragma_tok, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
case OMP_PARALLEL:
ret = cp_parser_omp_parallel (parser, pragma_tok, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
case OMP_SIMD:
ret = cp_parser_omp_simd (parser, pragma_tok, p_name,
- OMP_TARGET_CLAUSE_MASK, cclauses);
+ OMP_TARGET_CLAUSE_MASK, cclauses,
+ if_p);
break;
default:
gcc_unreachable ();
@@ -34959,7 +34973,7 @@ cp_parser_omp_target (cp_parser *parser,
else if (strcmp (p, "data") == 0)
{
cp_lexer_consume_token (parser->lexer);
- cp_parser_omp_target_data (parser, pragma_tok);
+ cp_parser_omp_target_data (parser, pragma_tok, if_p);
return true;
}
else if (strcmp (p, "enter") == 0)
@@ -34989,7 +35003,7 @@ cp_parser_omp_target (cp_parser *parser,
"#pragma omp target", pragma_tok);
pc = &OMP_TARGET_CLAUSES (stmt);
keep_next_level (true);
- OMP_TARGET_BODY (stmt) = cp_parser_omp_structured_block (parser);
+ OMP_TARGET_BODY (stmt) = cp_parser_omp_structured_block (parser, if_p);
SET_EXPR_LOCATION (stmt, pragma_tok->location);
add_stmt (stmt);
@@ -35065,7 +35079,7 @@ cp_parser_oacc_cache (cp_parser *parser,
| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE))
static tree
-cp_parser_oacc_data (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_oacc_data (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree stmt, clauses, block;
unsigned int save;
@@ -35075,7 +35089,7 @@ cp_parser_oacc_data (cp_parser *parser,
block = begin_omp_parallel ();
save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
stmt = finish_oacc_data (clauses, block);
return stmt;
@@ -35089,7 +35103,7 @@ cp_parser_oacc_data (cp_parser *parser,
( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
static tree
-cp_parser_oacc_host_data (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_oacc_host_data (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree stmt, clauses, block;
unsigned int save;
@@ -35099,7 +35113,7 @@ cp_parser_oacc_host_data (cp_parser *par
block = begin_omp_parallel ();
save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
stmt = finish_oacc_host_data (clauses, block);
return stmt;
@@ -35348,7 +35362,7 @@ cp_parser_oacc_enter_exit_data (cp_parse
static tree
cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name,
- omp_clause_mask mask, tree *cclauses)
+ omp_clause_mask mask, tree *cclauses, bool *if_p)
{
strcat (p_name, " loop");
mask |= OACC_LOOP_CLAUSE_MASK;
@@ -35366,7 +35380,7 @@ cp_parser_oacc_loop (cp_parser *parser,
tree block = begin_omp_structured_block ();
int save = cp_parser_begin_omp_structured_block (parser);
- tree stmt = cp_parser_omp_for_loop (parser, OACC_LOOP, clauses, NULL);
+ tree stmt = cp_parser_omp_for_loop (parser, OACC_LOOP, clauses, NULL, if_p);
cp_parser_end_omp_structured_block (parser, save);
add_stmt (finish_omp_structured_block (block));
@@ -35423,7 +35437,7 @@ cp_parser_oacc_loop (cp_parser *parser,
static tree
cp_parser_oacc_kernels_parallel (cp_parser *parser, cp_token *pragma_tok,
- char *p_name)
+ char *p_name, bool *if_p)
{
omp_clause_mask mask;
enum tree_code code;
@@ -35454,7 +35468,8 @@ cp_parser_oacc_kernels_parallel (cp_pars
tree block = begin_omp_parallel ();
tree clauses;
- cp_parser_oacc_loop (parser, pragma_tok, p_name, mask, &clauses);
+ cp_parser_oacc_loop (parser, pragma_tok, p_name, mask, &clauses,
+ if_p);
return finish_omp_construct (code, block, clauses);
}
}
@@ -35463,7 +35478,7 @@ cp_parser_oacc_kernels_parallel (cp_pars
tree block = begin_omp_parallel ();
unsigned int save = cp_parser_begin_omp_structured_block (parser);
- cp_parser_statement (parser, NULL_TREE, false, NULL);
+ cp_parser_statement (parser, NULL_TREE, false, if_p);
cp_parser_end_omp_structured_block (parser, save);
return finish_omp_construct (code, block, clauses);
}
@@ -35567,7 +35582,7 @@ cp_parser_omp_declare_simd (cp_parser *p
if (first_p)
{
while (cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA))
- cp_parser_pragma (parser, context);
+ cp_parser_pragma (parser, context, NULL);
switch (context)
{
case pragma_external:
@@ -36290,7 +36305,8 @@ cp_parser_omp_declare (cp_parser *parser
static tree
cp_parser_omp_taskloop (cp_parser *parser, cp_token *pragma_tok,
- char *p_name, omp_clause_mask mask, tree *cclauses)
+ char *p_name, omp_clause_mask mask, tree *cclauses,
+ bool *if_p)
{
tree clauses, sb, ret;
unsigned int save;
@@ -36313,11 +36329,11 @@ cp_parser_omp_taskloop (cp_parser *parse
cp_lexer_consume_token (parser->lexer);
if (!flag_openmp) /* flag_openmp_simd */
return cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
ret = cp_parser_omp_simd (parser, pragma_tok, p_name, mask,
- cclauses);
+ cclauses, if_p);
cp_parser_end_omp_structured_block (parser, save);
tree body = finish_omp_structured_block (sb);
if (ret == NULL)
@@ -36348,7 +36364,8 @@ cp_parser_omp_taskloop (cp_parser *parse
sb = begin_omp_structured_block ();
save = cp_parser_begin_omp_structured_block (parser);
- ret = cp_parser_omp_for_loop (parser, OMP_TASKLOOP, clauses, cclauses);
+ ret = cp_parser_omp_for_loop (parser, OMP_TASKLOOP, clauses, cclauses,
+ if_p);
cp_parser_end_omp_structured_block (parser, save);
add_stmt (finish_omp_structured_block (sb));
@@ -36511,7 +36528,7 @@ cp_parser_oacc_routine (cp_parser *parse
parser->oacc_routine->clauses = c_head;
while (cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA))
- cp_parser_pragma (parser, context);
+ cp_parser_pragma (parser, context, NULL);
if (first_p)
{
@@ -36638,7 +36655,7 @@ cp_finalize_oacc_routine (cp_parser *par
/* Main entry point to OpenMP statement pragmas. */
static void
-cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
tree stmt;
char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
@@ -36653,7 +36670,7 @@ cp_parser_omp_construct (cp_parser *pars
stmt = cp_parser_oacc_cache (parser, pragma_tok);
break;
case PRAGMA_OACC_DATA:
- stmt = cp_parser_oacc_data (parser, pragma_tok);
+ stmt = cp_parser_oacc_data (parser, pragma_tok, if_p);
break;
case PRAGMA_OACC_ENTER_DATA:
stmt = cp_parser_oacc_enter_exit_data (parser, pragma_tok, true);
@@ -36662,16 +36679,18 @@ cp_parser_omp_construct (cp_parser *pars
stmt = cp_parser_oacc_enter_exit_data (parser, pragma_tok, false);
break;
case PRAGMA_OACC_HOST_DATA:
- stmt = cp_parser_oacc_host_data (parser, pragma_tok);
+ stmt = cp_parser_oacc_host_data (parser, pragma_tok, if_p);
break;
case PRAGMA_OACC_KERNELS:
case PRAGMA_OACC_PARALLEL:
strcpy (p_name, "#pragma acc");
- stmt = cp_parser_oacc_kernels_parallel (parser, pragma_tok, p_name);
+ stmt = cp_parser_oacc_kernels_parallel (parser, pragma_tok, p_name,
+ if_p);
break;
case PRAGMA_OACC_LOOP:
strcpy (p_name, "#pragma acc");
- stmt = cp_parser_oacc_loop (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_oacc_loop (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OACC_UPDATE:
stmt = cp_parser_oacc_update (parser, pragma_tok);
@@ -36683,22 +36702,25 @@ cp_parser_omp_construct (cp_parser *pars
cp_parser_omp_atomic (parser, pragma_tok);
return;
case PRAGMA_OMP_CRITICAL:
- stmt = cp_parser_omp_critical (parser, pragma_tok);
+ stmt = cp_parser_omp_critical (parser, pragma_tok, if_p);
break;
case PRAGMA_OMP_DISTRIBUTE:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_distribute (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_distribute (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OMP_FOR:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_for (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_for (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OMP_MASTER:
- stmt = cp_parser_omp_master (parser, pragma_tok);
+ stmt = cp_parser_omp_master (parser, pragma_tok, if_p);
break;
case PRAGMA_OMP_PARALLEL:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_parallel (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_parallel (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OMP_SECTIONS:
strcpy (p_name, "#pragma omp");
@@ -36706,24 +36728,27 @@ cp_parser_omp_construct (cp_parser *pars
break;
case PRAGMA_OMP_SIMD:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_simd (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_simd (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OMP_SINGLE:
- stmt = cp_parser_omp_single (parser, pragma_tok);
+ stmt = cp_parser_omp_single (parser, pragma_tok, if_p);
break;
case PRAGMA_OMP_TASK:
- stmt = cp_parser_omp_task (parser, pragma_tok);
+ stmt = cp_parser_omp_task (parser, pragma_tok, if_p);
break;
case PRAGMA_OMP_TASKGROUP:
- stmt = cp_parser_omp_taskgroup (parser, pragma_tok);
+ stmt = cp_parser_omp_taskgroup (parser, pragma_tok, if_p);
break;
case PRAGMA_OMP_TASKLOOP:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_taskloop (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
case PRAGMA_OMP_TEAMS:
strcpy (p_name, "#pragma omp");
- stmt = cp_parser_omp_teams (parser, pragma_tok, p_name, mask, NULL);
+ stmt = cp_parser_omp_teams (parser, pragma_tok, p_name, mask, NULL,
+ if_p);
break;
default:
gcc_unreachable ();
@@ -37078,7 +37103,7 @@ cp_parser_initial_pragma (cp_token *firs
#pragma cilk grainsize = <VALUE>. */
static void
-cp_parser_cilk_grainsize (cp_parser *parser, cp_token *pragma_tok)
+cp_parser_cilk_grainsize (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
{
if (cp_parser_require (parser, CPP_EQ, RT_EQ))
{
@@ -37093,7 +37118,7 @@ cp_parser_cilk_grainsize (cp_parser *par
/* Make sure the next token is _Cilk_for, it is invalid otherwise. */
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_CILK_FOR))
- cp_parser_cilk_for (parser, exp);
+ cp_parser_cilk_for (parser, exp, if_p);
else
warning_at (cp_lexer_peek_token (parser->lexer)->location, 0,
"%<#pragma cilk grainsize%> is not followed by "
@@ -37107,7 +37132,7 @@ cp_parser_cilk_grainsize (cp_parser *par
regular lexer. */
static bool
-cp_parser_pragma (cp_parser *parser, enum pragma_context context)
+cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p)
{
cp_token *pragma_tok;
unsigned int id;
@@ -37265,19 +37290,19 @@ cp_parser_pragma (cp_parser *parser, enu
if (context != pragma_stmt && context != pragma_compound)
goto bad_stmt;
stmt = push_omp_privatization_clauses (false);
- cp_parser_omp_construct (parser, pragma_tok);
+ cp_parser_omp_construct (parser, pragma_tok, if_p);
pop_omp_privatization_clauses (stmt);
return true;
case PRAGMA_OMP_ORDERED:
stmt = push_omp_privatization_clauses (false);
- ret = cp_parser_omp_ordered (parser, pragma_tok, context);
+ ret = cp_parser_omp_ordered (parser, pragma_tok, context, if_p);
pop_omp_privatization_clauses (stmt);
return ret;
case PRAGMA_OMP_TARGET:
stmt = push_omp_privatization_clauses (false);
- ret = cp_parser_omp_target (parser, pragma_tok, context);
+ ret = cp_parser_omp_target (parser, pragma_tok, context, if_p);
pop_omp_privatization_clauses (stmt);
return ret;
@@ -37309,7 +37334,7 @@ cp_parser_pragma (cp_parser *parser, enu
cp_parser_error (parser, "for, while or do statement expected");
return false;
}
- cp_parser_iteration_statement (parser, NULL, true);
+ cp_parser_iteration_statement (parser, if_p, true);
return true;
}
@@ -37321,7 +37346,7 @@ cp_parser_pragma (cp_parser *parser, enu
break;
}
stmt = push_omp_privatization_clauses (false);
- cp_parser_cilk_simd (parser, pragma_tok);
+ cp_parser_cilk_simd (parser, pragma_tok, if_p);
pop_omp_privatization_clauses (stmt);
return true;
@@ -37336,7 +37361,7 @@ cp_parser_pragma (cp_parser *parser, enu
/* Ignore the pragma if Cilk Plus is not enabled. */
if (flag_cilkplus)
{
- cp_parser_cilk_grainsize (parser, pragma_tok);
+ cp_parser_cilk_grainsize (parser, pragma_tok, if_p);
return true;
}
else
@@ -37663,7 +37688,7 @@ cp_parser_cilk_simd_all_clauses (cp_pars
/* Main entry-point for parsing Cilk Plus <#pragma simd> for loops. */
static void
-cp_parser_cilk_simd (cp_parser *parser, cp_token *pragma_token)
+cp_parser_cilk_simd (cp_parser *parser, cp_token *pragma_token, bool *if_p)
{
tree clauses = cp_parser_cilk_simd_all_clauses (parser, pragma_token);
@@ -37679,7 +37704,7 @@ cp_parser_cilk_simd (cp_parser *parser,
tree sb = begin_omp_structured_block ();
int save = cp_parser_begin_omp_structured_block (parser);
- tree ret = cp_parser_omp_for_loop (parser, CILK_SIMD, clauses, NULL);
+ tree ret = cp_parser_omp_for_loop (parser, CILK_SIMD, clauses, NULL, if_p);
if (ret)
cpp_validate_cilk_plus_loop (OMP_FOR_BODY (ret));
cp_parser_end_omp_structured_block (parser, save);
@@ -37691,7 +37716,7 @@ cp_parser_cilk_simd (cp_parser *parser,
when errors happen and CILK_FOR tree on success. */
static tree
-cp_parser_cilk_for (cp_parser *parser, tree grain)
+cp_parser_cilk_for (cp_parser *parser, tree grain, bool *if_p)
{
if (cp_lexer_next_token_is_not_keyword (parser->lexer, RID_CILK_FOR))
gcc_unreachable ();
@@ -37704,7 +37729,7 @@ cp_parser_cilk_for (cp_parser *parser, t
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain;
clauses = finish_omp_clauses (clauses, false);
- tree ret = cp_parser_omp_for_loop (parser, CILK_FOR, clauses, NULL);
+ tree ret = cp_parser_omp_for_loop (parser, CILK_FOR, clauses, NULL, if_p);
if (ret)
cpp_validate_cilk_plus_loop (ret);
else
--- gcc/testsuite/c-c++-common/Wparentheses-1.c.jj 2016-04-15 10:26:22.876317152 +0200
+++ gcc/testsuite/c-c++-common/Wparentheses-1.c 2016-04-15 10:38:01.180619878 +0200
@@ -0,0 +1,39 @@
+/* PR c/70436 */
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int a, b, c[101], d[101], e[101], f[101];
+
+void
+f1 (void)
+{
+ int i;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma GCC ivdep
+ for (i = 0; i < 100; i++)
+ if (b)
+ c[i] = d[i] + e[i];
+ else
+ f[i] = d[i] * e[i];
+
+ if (a)
+ #pragma GCC ivdep
+ for (i = 0; i < 100; i++)
+ {
+ if (b)
+ c[i] = d[i] + e[i];
+ else
+ f[i] = d[i] * e[i];
+ }
+
+ if (a)
+ #pragma GCC ivdep
+ for (i = 0; i < 100; i++)
+ {
+ if (b)
+ c[i] = d[i] + e[i];
+ }
+ else
+ f[i] = d[i] * e[i];
+}
--- gcc/testsuite/c-c++-common/gomp/Wparentheses-1.c.jj 2016-04-15 09:54:19.665120654 +0200
+++ gcc/testsuite/c-c++-common/gomp/Wparentheses-1.c 2016-04-15 10:52:15.990770896 +0200
@@ -0,0 +1,338 @@
+/* PR c/70436 */
+/* { dg-additional-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+f1 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp for
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskloop
+ for (i = 0; i < 10; i++)
+ if (b)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskloop simd
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp critical
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for simd schedule(runtime)
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp master
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp single
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp task
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskgroup
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp taskloop
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp critical
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for simd schedule(dynamic, 5)
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp master
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp single
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp task
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp taskgroup
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp taskloop simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
+
+void
+f2 (int d, int e, int f)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp ordered
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (d) /* { dg-warning "ambiguous" } */
+ #pragma omp ordered threads
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (e)
+ #pragma omp ordered
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (f)
+ #pragma omp ordered threads
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
--- gcc/testsuite/c-c++-common/gomp/Wparentheses-2.c.jj 2016-04-15 09:54:23.415068282 +0200
+++ gcc/testsuite/c-c++-common/gomp/Wparentheses-2.c 2016-04-15 10:37:35.553975752 +0200
@@ -0,0 +1,452 @@
+/* PR c/70436 */
+/* { dg-additional-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+void f1 (void);
+#pragma omp declare target to (bar, baz, f1, a, b, c)
+
+void
+f1 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+}
+
+void
+f2 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp target teams distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp target teams distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp target teams distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp target teams distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp target
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target parallel
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ { {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ } }
+
+ if (a)
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ { {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ }
+ }
+ else
+ baz ();
+}
+
+void
+f3 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp target
+ #pragma omp teams distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp target
+ #pragma omp teams distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp target
+ #pragma omp teams distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
+
+void
+f4 (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target data map (tofrom: b)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target data map (tofrom: b)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
--- gcc/testsuite/c-c++-common/gomp/Wparentheses-3.c.jj 2016-04-15 11:18:32.694942971 +0200
+++ gcc/testsuite/c-c++-common/gomp/Wparentheses-3.c 2016-04-15 11:19:31.616127825 +0200
@@ -0,0 +1,338 @@
+/* PR c/70436 */
+/* { dg-additional-options "-Wparentheses -fno-openmp" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+f1 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ while (1)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp for
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskloop
+ for (i = 0; i < 10; i++)
+ if (b)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+ else
+ bar ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskloop simd
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp critical
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp for simd schedule(runtime)
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp master
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp single
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp task
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp taskgroup
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp taskloop
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp critical
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp for simd schedule(dynamic, 5)
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp master
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp single
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp task
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp taskgroup
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp taskloop simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
+
+void
+f2 (int d, int e, int f)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp ordered
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (d) /* { dg-warning "ambiguous" } */
+ #pragma omp ordered threads
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (e)
+ #pragma omp ordered
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (f)
+ #pragma omp ordered threads
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
--- gcc/testsuite/c-c++-common/gomp/Wparentheses-4.c.jj 2016-04-15 11:18:35.748900721 +0200
+++ gcc/testsuite/c-c++-common/gomp/Wparentheses-4.c 2016-04-15 11:19:38.948026392 +0200
@@ -0,0 +1,452 @@
+/* PR c/70436 */
+/* { dg-additional-options "-Wparentheses -fno-openmp" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+void f1 (void);
+#pragma omp declare target to (bar, baz, f1, a, b, c)
+
+void
+f1 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+}
+
+void
+f2 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp target teams distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target teams
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp target teams distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp target teams distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp target teams distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target teams
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp target
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target parallel
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma omp target simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ { {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ } }
+
+ if (a)
+ #pragma omp target simd collapse(2)
+ for (i = 0; i < 10; i++)
+ { {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ }
+ }
+ else
+ baz ();
+}
+
+void
+f3 (void)
+{
+ int i, j;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams distribute
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ for (i = 0; i < 10; i++)
+ #pragma omp target
+ #pragma omp teams distribute simd
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute parallel for
+ for (i = 0; i < 10; i++)
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma omp parallel for
+ for (j = 0; j < 10; j++)
+ if (c)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams distribute parallel for simd collapse(2)
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target
+ #pragma omp teams
+ #pragma omp parallel
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ {
+ #pragma omp target
+ #pragma omp teams distribute simd
+ for (i = 0; i < 10; ++i)
+ if (b)
+ bar ();
+ }
+ else baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams distribute parallel for collapse(2)
+ for (i = 0; i < 10; i++)
+ {
+ for (j = 0; j < 10; j++)
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ for (i = 0; i < 10; i++)
+ #pragma omp target
+ #pragma omp teams distribute parallel for simd
+ for (j = 0; j < 10; j++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target
+ #pragma omp teams
+ #pragma omp parallel
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
+
+void
+f4 (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma omp target data map (tofrom: b)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma omp target data map (tofrom: b)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+}
--- gcc/testsuite/c-c++-common/cilk-plus/PS/Wparentheses-1.c.jj 2016-04-15 10:18:36.744799555 +0200
+++ gcc/testsuite/c-c++-common/cilk-plus/PS/Wparentheses-1.c 2016-04-15 10:37:50.433769118 +0200
@@ -0,0 +1,41 @@
+/* PR c/70436 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus -Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+f1 (void)
+{
+ int i;
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma simd
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma simd
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+}
--- gcc/testsuite/c-c++-common/cilk-plus/CK/Wparentheses-1.c.jj 2016-04-15 10:17:10.817996634 +0200
+++ gcc/testsuite/c-c++-common/cilk-plus/CK/Wparentheses-1.c 2016-04-15 10:37:47.641807890 +0200
@@ -0,0 +1,69 @@
+/* PR c/70436 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus -Wparentheses" } */
+/* { dg-additional-options "-std=gnu99" { target c } } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+
+void
+f1 (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ _Cilk_for (int i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ _Cilk_for (int i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ _Cilk_for (int i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+}
+
+void
+f2 (void)
+{
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma cilk grainsize = 2
+ _Cilk_for (int i = 0; i < 10; i++)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a)
+ #pragma cilk grainsize = 2
+ _Cilk_for (int i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma cilk grainsize = 2
+ _Cilk_for (int i = 0; i < 10; i++)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+}
--- gcc/testsuite/c-c++-common/goacc/Wparentheses-1.c.jj 2016-04-15 10:50:51.488942022 +0200
+++ gcc/testsuite/c-c++-common/goacc/Wparentheses-1.c 2016-04-15 10:53:04.899093067 +0200
@@ -0,0 +1,174 @@
+/* PR c/70436 */
+/* { dg-additional-options "-Wparentheses" } */
+
+int a, b, c;
+void bar (void);
+void baz (void);
+#pragma acc routine
+void bar2 (void);
+#pragma acc routine
+void baz2 (void);
+
+void
+f1 (void)
+{
+ int i, d[10] = { 0 };
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc data copyin (d[0:10])
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ #pragma acc data copyin (d[0:10])
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc host_data use_device (d)
+ if (b)
+ bar ();
+ else
+ baz ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc kernels
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc kernels
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc parallel
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+
+ if (a) /* { dg-warning "ambiguous" } */
+ #pragma acc parallel loop
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+
+ (void) d[0];
+
+ if (a)
+ #pragma acc data copyin (d[0:10])
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ if (a)
+ #pragma acc data copyin (d[0:10])
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ #pragma acc data copyin (d[0:10])
+ if (a)
+ #pragma acc host_data use_device (d)
+ {
+ if (b)
+ bar ();
+ else
+ baz ();
+ }
+
+ #pragma acc data copyin (d[0:10])
+ if (a)
+ #pragma acc host_data use_device (d)
+ {
+ if (b)
+ bar ();
+ }
+ else
+ baz ();
+
+ if (a)
+ #pragma acc kernels
+ {
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+ }
+
+ if (a)
+ #pragma acc kernels
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+ }
+
+ if (a)
+ #pragma acc parallel
+ {
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+ }
+
+ if (a)
+ #pragma acc parallel loop
+ for (i = 0; i < 10; i++)
+ {
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+ }
+
+ if (a)
+ {
+ #pragma acc parallel loop
+ for (i = 0; i < 10; i++)
+ if (b)
+ bar2 ();
+ else
+ baz2 ();
+ }
+}
+
+#pragma acc routine vector
+void
+f2 (int *a, int b, int c)
+{
+ int i;
+
+ if (b) /* { dg-warning "ambiguous" } */
+ #pragma acc loop vector
+ for (i = 0; i < 10; i++)
+ if (c)
+ a[i] = a[i] + 1;
+ else
+ a[i] = a[i] + 2;
+
+ if (b)
+ #pragma acc loop vector
+ for (i = 0; i < 10; i++)
+ {
+ if (c)
+ a[i] = a[i] + 1;
+ else
+ a[i] = a[i] + 2;
+ }
+}
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-04-15 13:07 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13 14:14 C PATCH to overhaul warning about dangling else (PR c/70436) Marek Polacek
2016-04-13 14:16 ` Jakub Jelinek
2016-04-13 14:19 ` Marek Polacek
2016-04-13 15:00 ` Bernd Schmidt
2016-04-13 15:56 ` Marek Polacek
2016-04-13 15:10 ` Jakub Jelinek
2016-04-13 15:43 ` Marek Polacek
2016-04-13 15:45 ` Jakub Jelinek
2016-04-15 13:07 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).