Bug 68516 - ICE: OpenMP with simd collapse
Summary: ICE: OpenMP with simd collapse
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-24 11:56 UTC by Chiu-Hsiang Hsu
Modified: 2015-12-04 14:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chiu-Hsiang Hsu 2015-11-24 11:56:57 UTC
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-5.2.0/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.2.0 (GCC)
========================================
$ cat test1.c
int a[100];
                                         
int main()
{
    #pragma omp simd collapse(2)
    for (int i = 0; i < 10; i++) {
        for (int k = a[i]; k < 0; k++) {
            a[i] = a[i] - 1;
        }
    }
                                         
    return 0;
}
========================================
$ gcc -O3 -fopenmp test1.c
test1.c: In function ‘main’:
test1.c:7:23: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
        for (int k = a[i]; k < 0; k++) {
                    ^
test1.c:3:5: internal compiler error: in expand_one_var, at cfgexpand.c:1339
int main()
    ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
========================================
$ cat test2.c
int a[100];
                                         
int main()
{
    #pragma omp for simd collapse(2)
    for (int i = 0; i < 10; i++) {
        for (int k = a[i]; k < 0; k++) {
            a[i] = a[i] - 1;
        }
    }
                                         
    return 0;
}
========================================
$ gcc -O3 -fopenmp test2.c
test2.c: In function ‘main’:
test2.c:7:23: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1801
        for (int k = a[i]; k < 0; k++) {
                    ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
========================================
Comment 1 Jakub Jelinek 2015-12-04 14:47:23 UTC
This is not valid OpenMP, GCC trunk properly rejects it:
pr68516.c: In function ‘main’:
pr68516.c:7:23: error: initializer expression refers to iteration variable ‘i’
         for (int k = a[i]; k < 0; k++) {
                      ~^~~
As it is just ICE on invalid, not going to backport the fixes (which are related to the OpenMP 4.5 wording that simplified this anyway).
The OpenMP 4.0 rule is:
"The iteration count for each associated loop is computed before entry to the outermost loop. If execution of any associated loop changes any of the values used to compute any of the iteration counts, then the behavior is unspecified."
Marking as fixed in GCC 6+.