Bug 85696 - OpenMP with variably modified and default(none) won't compile
Summary: OpenMP with variably modified and default(none) won't compile
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 8.1.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: openmp, rejects-valid
: 61342 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-08 14:17 UTC by gcc-bugzilla
Modified: 2023-04-06 06:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-05-09 00:00:00


Attachments
gcc -v (Archlinux) (480 bytes, text/plain)
2018-05-08 14:17 UTC, gcc-bugzilla
Details
pologies, wrong gcc version. The error of 8.1.0 is exactly the same though. (471 bytes, text/plain)
2018-05-08 14:22 UTC, gcc-bugzilla
Details
minimal example (98 bytes, text/plain)
2018-05-08 14:23 UTC, gcc-bugzilla
Details
gcc9-pr85696.patch (863 bytes, patch)
2018-05-09 11:18 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description gcc-bugzilla 2018-05-08 14:17:15 UTC
Created attachment 44085 [details]
gcc -v (Archlinux)

The following trivial code

    void foo(int n, int a[][n])
    {
    #pragma omp parallel shared(a) default(none)
        a[23][0] = 42;
    }

fails to compile:

    $ gcc -c -fopenmp minimal.c 
    minimal.c: In function ‘foo’:
    minimal.c:3:6: error: ‘n.0’ not specified in enclosing ‘parallel’
         a[23][0] = 42;
          ^
    minimal.c:2:9: error: enclosing ‘parallel’
     #pragma omp parallel shared(a) default(none)
             ^~~

It appears that there is an internal copy n.0 of n to compute the index to any further access to a. This internal copy is not handled properly in the default(none) parallel region.

Interestingly in the 004t.gimple pass, it is actually listed as shared(n.0):

    #pragma omp parallel default(none) shared(a) shared(n.0)


The bug exists at least since 4.8 and was first reported at https://stackoverflow.com/q/47081274/620382
Comment 1 gcc-bugzilla 2018-05-08 14:22:27 UTC
Created attachment 44086 [details]
pologies, wrong gcc version. The error of 8.1.0 is exactly the same though.
Comment 2 gcc-bugzilla 2018-05-08 14:23:14 UTC
Created attachment 44087 [details]
minimal example
Comment 3 Jakub Jelinek 2018-05-09 11:18:15 UTC
Created attachment 44096 [details]
gcc9-pr85696.patch

Untested fix.
Comment 4 Jakub Jelinek 2018-05-11 07:43:21 UTC
Author: jakub
Date: Fri May 11 07:42:50 2018
New Revision: 260156

URL: https://gcc.gnu.org/viewcvs?rev=260156&root=gcc&view=rev
Log:
	PR c/85696
	* c-omp.c (c_omp_predetermined_sharing): Return
	OMP_CLAUSE_DEFAULT_SHARED for artificial vars with integral type.

	* cp-tree.h (cxx_omp_predetermined_sharing_1): New prototype.
	* cp-gimplify.c (cxx_omp_predetermined_sharing): New wrapper around
	cxx_omp_predetermined_sharing_1.  Rename old function to ...
	(cxx_omp_predetermined_sharing_1): ... this.
	* semantics.c (finish_omp_clauses): Use cxx_omp_predetermined_sharing_1
	instead of cxx_omp_predetermined_sharing.

	* c-c++-common/gomp/pr85696.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/gomp/pr85696.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-omp.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2018-05-11 08:34:27 UTC
Fixed for 9.1+ so far, backports queued.
Comment 6 Jakub Jelinek 2018-05-30 07:35:28 UTC
Author: jakub
Date: Wed May 30 07:34:56 2018
New Revision: 260917

URL: https://gcc.gnu.org/viewcvs?rev=260917&root=gcc&view=rev
Log:
	Backported from mainline
	2018-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/85696
	* c-omp.c (c_omp_predetermined_sharing): Return
	OMP_CLAUSE_DEFAULT_SHARED for artificial vars with integral type.

	* cp-tree.h (cxx_omp_predetermined_sharing_1): New prototype.
	* cp-gimplify.c (cxx_omp_predetermined_sharing): New wrapper around
	cxx_omp_predetermined_sharing_1.  Rename old function to ...
	(cxx_omp_predetermined_sharing_1): ... this.
	* semantics.c (finish_omp_clauses): Use cxx_omp_predetermined_sharing_1
	instead of cxx_omp_predetermined_sharing.

	* c-c++-common/gomp/pr85696.c: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/c-c++-common/gomp/pr85696.c
Modified:
    branches/gcc-8-branch/gcc/c-family/ChangeLog
    branches/gcc-8-branch/gcc/c-family/c-omp.c
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/cp-gimplify.c
    branches/gcc-8-branch/gcc/cp/cp-tree.h
    branches/gcc-8-branch/gcc/cp/semantics.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2018-05-30 07:59:30 UTC
Fixed for 8.2+.
Comment 8 Jakub Jelinek 2018-06-22 21:25:36 UTC
Author: jakub
Date: Fri Jun 22 21:25:04 2018
New Revision: 261963

URL: https://gcc.gnu.org/viewcvs?rev=261963&root=gcc&view=rev
Log:
	Backported from mainline
	2018-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/85696
	* c-omp.c (c_omp_predetermined_sharing): Return
	OMP_CLAUSE_DEFAULT_SHARED for artificial vars with integral type.

	* c-typeck.c (c_finish_omp_clauses): Don't use
	c_omp_predetermined_sharing, instead just check TREE_READONLY.

	* cp-tree.h (cxx_omp_predetermined_sharing_1): New prototype.
	* cp-gimplify.c (cxx_omp_predetermined_sharing): New wrapper around
	cxx_omp_predetermined_sharing_1.  Rename old function to ...
	(cxx_omp_predetermined_sharing_1): ... this.
	* semantics.c (finish_omp_clauses): Use cxx_omp_predetermined_sharing_1
	instead of cxx_omp_predetermined_sharing.

	* c-c++-common/gomp/pr85696.c: New test.

Modified:
    branches/gcc-7-branch/gcc/c-family/ChangeLog
    branches/gcc-7-branch/gcc/c-family/c-omp.c
    branches/gcc-7-branch/gcc/c/ChangeLog
    branches/gcc-7-branch/gcc/c/c-typeck.c
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/cp-gimplify.c
    branches/gcc-7-branch/gcc/cp/cp-tree.h
    branches/gcc-7-branch/gcc/cp/semantics.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2018-06-22 21:27:57 UTC
Author: jakub
Date: Fri Jun 22 21:27:25 2018
New Revision: 261964

URL: https://gcc.gnu.org/viewcvs?rev=261964&root=gcc&view=rev
Log:
	Backported from mainline
	2018-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/85696
	* c-omp.c (c_omp_predetermined_sharing): Return
	OMP_CLAUSE_DEFAULT_SHARED for artificial vars with integral type.

	* c-typeck.c (c_finish_omp_clauses): Don't use
	c_omp_predetermined_sharing, instead just check TREE_READONLY.

	* cp-tree.h (cxx_omp_predetermined_sharing_1): New prototype.
	* cp-gimplify.c (cxx_omp_predetermined_sharing): New wrapper around
	cxx_omp_predetermined_sharing_1.  Rename old function to ...
	(cxx_omp_predetermined_sharing_1): ... this.
	* semantics.c (finish_omp_clauses): Use cxx_omp_predetermined_sharing_1
	instead of cxx_omp_predetermined_sharing.

	* c-c++-common/gomp/pr85696.c: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/c-c++-common/gomp/pr85696.c
Comment 10 Jakub Jelinek 2021-02-12 11:37:44 UTC
*** Bug 61342 has been marked as a duplicate of this bug. ***
Comment 11 zhonghao 2023-04-06 05:40:20 UTC
Is this bug really fixed? I tried the latest version, but it is still rejected:

<source>:1:28: error: use of parameter outside function body before ']' token
    1 |   void foo(int n, int a[][n])
      |                            ^
<source>: In function 'void foo(...)':
<source>:4:9: error: 'a' was not declared in this scope
    4 |         a[23][0] = 42;
      |         ^
Compiler returned: 1
Comment 12 Jakub Jelinek 2023-04-06 06:57:48 UTC
If you are trying to compile C code which isn't valid C++ by C++, then such an error is expected.