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
Created attachment 44086 [details] pologies, wrong gcc version. The error of 8.1.0 is exactly the same though.
Created attachment 44087 [details] minimal example
Created attachment 44096 [details] gcc9-pr85696.patch Untested fix.
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
Fixed for 9.1+ so far, backports queued.
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
Fixed for 8.2+.
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
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
*** Bug 61342 has been marked as a duplicate of this bug. ***
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
If you are trying to compile C code which isn't valid C++ by C++, then such an error is expected.