openmp: Check for PARM_DECL before using C_ARRAY_PARAMETER or DECL_ARRAY_PARAMETER_P [PR96867]

The C++ macro performs a PARM_DECL_CHECK, so will ICE if not tested on a PARM_DECL,
C_ARRAY_PARAMETER doesn't, but probably should, otherwise it is testing e.g.
C_DECL_VARIABLE_SIZE on VAR_DECLs.

2020-09-01  Jakub Jelinek  <jakub@redhat.com>

	PR c++/96867
	* c-typeck.c (handle_omp_array_sections_1): Test C_ARRAY_PARAMETER
	only on PARM_DECLs.

	* semantics.c (handle_omp_array_sections_1): Test
	DECL_ARRAY_PARAMETER_P only on PARM_DECLs.

	* c-c++-common/gomp/pr96867.c: New test.
This commit is contained in:
Jakub Jelinek 2020-09-01 09:17:58 +02:00
parent ef688fdfc6
commit a37b0cccf4
3 changed files with 11 additions and 2 deletions

View file

@ -13298,7 +13298,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
{
if (length == NULL_TREE)
{
if (C_ARRAY_PARAMETER (ret))
if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
error_at (OMP_CLAUSE_LOCATION (c),
"for array function parameter length expression "
"must be specified");

View file

@ -5083,7 +5083,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
{
if (length == NULL_TREE)
{
if (DECL_ARRAY_PARAMETER_P (ret))
if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
error_at (OMP_CLAUSE_LOCATION (c),
"for array function parameter length expression "
"must be specified");

View file

@ -0,0 +1,9 @@
/* PR c++/96867 */
int *v;
void
foo (int x)
{
#pragma omp target update to (x, v[:]) /* { dg-error "for pointer type length expression must be specified" } */
}