aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2017-05-12 11:33:18 +0200
committerThomas Schwinge <tschwinge@gcc.gnu.org>2017-05-12 11:33:18 +0200
commit1e47f02b6390db82d2e7dcc7eec3bb888c78318a (patch)
tree0cc51c36b180d9add1a3f320701f67c275ab7b12 /gcc/c/c-parser.c
parent62ffe9207c7568fe9d28891caa2bf3aa18664375 (diff)
downloadgcc-1e47f02b6390db82d2e7dcc7eec3bb888c78318a.zip
gcc-1e47f02b6390db82d2e7dcc7eec3bb888c78318a.tar.gz
gcc-1e47f02b6390db82d2e7dcc7eec3bb888c78318a.tar.bz2
OpenACC C front end maintenance: c_parser_oacc_single_int_clause
gcc/c/ * c-parser.c (c_parser_omp_clause_num_gangs) (c_parser_omp_clause_num_workers) (c_parser_omp_clause_vector_length): Merge functions into... (c_parser_oacc_single_int_clause): ... this new function. Adjust all users. gcc/testsuite/ * c-c++-common/goacc/parallel-dims-1.c: New file. * c-c++-common/goacc/parallel-dims-2.c: Likewise. From-SVN: r247960
Diffstat (limited to 'gcc/c/c-parser.c')
-rw-r--r--gcc/c/c-parser.c172
1 files changed, 47 insertions, 125 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 9398652..90d2d17 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -11339,51 +11339,6 @@ c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
return c;
}
-/* OpenACC:
- num_gangs ( expression ) */
-
-static tree
-c_parser_omp_clause_num_gangs (c_parser *parser, tree list)
-{
- location_t num_gangs_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- location_t expr_loc = c_parser_peek_token (parser)->location;
- c_expr expr = c_parser_expression (parser);
- expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
- tree c, t = expr.value;
- t = c_fully_fold (t, false, NULL);
-
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
-
- if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
- {
- c_parser_error (parser, "expected integer expression");
- return list;
- }
-
- /* Attempt to statically determine when the number isn't positive. */
- c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
- build_int_cst (TREE_TYPE (t), 0));
- protected_set_expr_location (c, expr_loc);
- if (c == boolean_true_node)
- {
- warning_at (expr_loc, 0,
- "%<num_gangs%> value must be positive");
- t = integer_one_node;
- }
-
- check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs");
-
- c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS);
- OMP_CLAUSE_NUM_GANGS_EXPR (c) = t;
- OMP_CLAUSE_CHAIN (c) = list;
- list = c;
- }
-
- return list;
-}
-
/* OpenMP 2.5:
num_threads ( expression ) */
@@ -11671,48 +11626,54 @@ c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list)
}
/* OpenACC:
- num_workers ( expression ) */
+ num_gangs ( expression )
+ num_workers ( expression )
+ vector_length ( expression ) */
static tree
-c_parser_omp_clause_num_workers (c_parser *parser, tree list)
+c_parser_oacc_single_int_clause (c_parser *parser, omp_clause_code code,
+ tree list)
{
- location_t num_workers_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- location_t expr_loc = c_parser_peek_token (parser)->location;
- c_expr expr = c_parser_expression (parser);
- expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
- tree c, t = expr.value;
- t = c_fully_fold (t, false, NULL);
+ location_t loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ return list;
- if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
- {
- c_parser_error (parser, "expected integer expression");
- return list;
- }
+ location_t expr_loc = c_parser_peek_token (parser)->location;
+ c_expr expr = c_parser_expression (parser);
+ expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
+ tree c, t = expr.value;
+ t = c_fully_fold (t, false, NULL);
- /* Attempt to statically determine when the number isn't positive. */
- c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
- build_int_cst (TREE_TYPE (t), 0));
- protected_set_expr_location (c, expr_loc);
- if (c == boolean_true_node)
- {
- warning_at (expr_loc, 0,
- "%<num_workers%> value must be positive");
- t = integer_one_node;
- }
+ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
- check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers");
+ if (t == error_mark_node)
+ return list;
+ else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
+ {
+ error_at (expr_loc, "%qs expression must be integral",
+ omp_clause_code_name[code]);
+ return list;
+ }
- c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS);
- OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t;
- OMP_CLAUSE_CHAIN (c) = list;
- list = c;
+ /* Attempt to statically determine when the number isn't positive. */
+ c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
+ build_int_cst (TREE_TYPE (t), 0));
+ protected_set_expr_location (c, expr_loc);
+ if (c == boolean_true_node)
+ {
+ warning_at (expr_loc, 0,
+ "%qs value must be positive",
+ omp_clause_code_name[code]);
+ t = integer_one_node;
}
- return list;
+ check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
+
+ c = build_omp_clause (loc, code);
+ OMP_CLAUSE_OPERAND (c, 0) = t;
+ OMP_CLAUSE_CHAIN (c) = list;
+ return c;
}
/* OpenACC:
@@ -12354,51 +12315,6 @@ c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
return c;
}
-/* OpenACC:
- vector_length ( expression ) */
-
-static tree
-c_parser_omp_clause_vector_length (c_parser *parser, tree list)
-{
- location_t vector_length_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- location_t expr_loc = c_parser_peek_token (parser)->location;
- c_expr expr = c_parser_expression (parser);
- expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
- tree c, t = expr.value;
- t = c_fully_fold (t, false, NULL);
-
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
-
- if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
- {
- c_parser_error (parser, "expected integer expression");
- return list;
- }
-
- /* Attempt to statically determine when the number isn't positive. */
- c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
- build_int_cst (TREE_TYPE (t), 0));
- protected_set_expr_location (c, expr_loc);
- if (c == boolean_true_node)
- {
- warning_at (expr_loc, 0,
- "%<vector_length%> value must be positive");
- t = integer_one_node;
- }
-
- check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length");
-
- c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH);
- OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t;
- OMP_CLAUSE_CHAIN (c) = list;
- list = c;
- }
-
- return list;
-}
-
/* OpenMP 4.0:
inbranch
notinbranch */
@@ -13283,11 +13199,15 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
c_name = "link";
break;
case PRAGMA_OACC_CLAUSE_NUM_GANGS:
- clauses = c_parser_omp_clause_num_gangs (parser, clauses);
+ clauses = c_parser_oacc_single_int_clause (parser,
+ OMP_CLAUSE_NUM_GANGS,
+ clauses);
c_name = "num_gangs";
break;
case PRAGMA_OACC_CLAUSE_NUM_WORKERS:
- clauses = c_parser_omp_clause_num_workers (parser, clauses);
+ clauses = c_parser_oacc_single_int_clause (parser,
+ OMP_CLAUSE_NUM_WORKERS,
+ clauses);
c_name = "num_workers";
break;
case PRAGMA_OACC_CLAUSE_PRESENT:
@@ -13341,7 +13261,9 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
c_name, clauses);
break;
case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH:
- clauses = c_parser_omp_clause_vector_length (parser, clauses);
+ clauses = c_parser_oacc_single_int_clause (parser,
+ OMP_CLAUSE_VECTOR_LENGTH,
+ clauses);
c_name = "vector_length";
break;
case PRAGMA_OACC_CLAUSE_WAIT: