Bug 90954 - ICE: combining undefined behavior sanitizer with openmp
Summary: ICE: combining undefined behavior sanitizer with openmp
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 8.3.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2019-06-21 09:55 UTC by Frans van der Have
Modified: 2019-08-30 13:28 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-06-24 00:00:00


Attachments
preprocessed source resulting from the gcc run when the ICE occurs (3.79 KB, text/plain)
2019-06-21 09:55 UTC, Frans van der Have
Details
gcc10-pr90954.patch (612 bytes, patch)
2019-06-24 11:24 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frans van der Have 2019-06-21 09:55:48 UTC
Created attachment 46506 [details]
preprocessed source resulting from the gcc run when the ICE occurs

When compiling OpenMP parallel code with the undefined behavior sanitizer enabled, I encountered an internal compiler error. I reduced the problem to the following small example: 
--- start bug.c --- 
#include <stdio.h>
#include <omp.h>


int main(void)
{
    float     sum = 0.0f;
    int       i;

#pragma omp parallel for
    for (i = 0; i < 10; i++) {
        float a, b;
        a = 1.0f;
        b = 2.0f;
#pragma omp atomic
        sum += a / b;
    }

    printf("sum = %g \n", sum); 
    return 0;
}
--- end bug.c --- 
Running it with the version of gcc-8 that is in current Ubuntu 18.04 LTS 
without the undefined behavior sanitizer has the expected result:

$ gcc-8 -v -save-temps -Wall -Wextra -fopenmp -o bug bug.c 
Using built-in specs.
COLLECT_GCC=gcc-8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.3.0-6ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu -D_REENTRANT bug.c -mtune=generic -march=x86-64 -Wall -Wextra -fopenmp -fpch-preprocess -fstack-protector-strong -Wformat-security -o bug.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -fpreprocessed bug.i -quiet -dumpbase bug.c -mtune=generic -march=x86-64 -auxbase bug -Wall -Wextra -version -fopenmp -fstack-protector-strong -Wformat-security -o bug.s
GNU C17 (Ubuntu 8.3.0-6ubuntu1~18.04.1) version 8.3.0 (x86_64-linux-gnu)
	compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Ubuntu 8.3.0-6ubuntu1~18.04.1) version 8.3.0 (x86_64-linux-gnu)
	compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8630479b05639af80099f29538a134fa
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 as -v --64 -o bug.o bug.s
GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.30
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/8/libgomp.spec
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/8/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/8/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper -plugin-opt=-fresolution=bug.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o bug /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o /usr/lib/gcc/x86_64-linux-gnu/8/crtoffloadbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/8 -L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/8/../../.. bug.o -lgomp -lgcc --push-state --as-needed -lgcc_s --pop-state -lpthread -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o /usr/lib/gcc/x86_64-linux-gnu/8/crtoffloadend.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'

$ ./bug 
sum = 5 

However, running it with the undefined behavior sanitizer results in an internal compiler error: 

$ gcc-8 -v -save-temps -Wall -Wextra -fsanitize=undefined -fopenmp -o bug bug.c  
Using built-in specs.
COLLECT_GCC=gcc-8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.3.0-6ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fsanitize=undefined' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu -D_REENTRANT bug.c -mtune=generic -march=x86-64 -Wall -Wextra -fsanitize=undefined -fopenmp -fpch-preprocess -fstack-protector-strong -Wformat-security -o bug.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fsanitize=undefined' '-fopenmp' '-o' 'bug' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -fpreprocessed bug.i -quiet -dumpbase bug.c -mtune=generic -march=x86-64 -auxbase bug -Wall -Wextra -version -fsanitize=undefined -fopenmp -fstack-protector-strong -Wformat-security -o bug.s
GNU C17 (Ubuntu 8.3.0-6ubuntu1~18.04.1) version 8.3.0 (x86_64-linux-gnu)
	compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Ubuntu 8.3.0-6ubuntu1~18.04.1) version 8.3.0 (x86_64-linux-gnu)
	compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8630479b05639af80099f29538a134fa
bug.c: In function ‘main’:
bug.c:16:9: internal compiler error: in c_finish_omp_atomic, at c-family/c-omp.c:303
         sum += a / b;
         ^~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.

--- end of output --- 

The problem also occurs in other versions of gcc that are included in Ubuntu. 
Attached is "bug.i" from the run that produces the ICE.
Comment 1 Martin Liška 2019-06-21 11:14:52 UTC
Confirmed, it's old, starting with GCC 4.9.0 where -fsanitize=undefined was added. Can you please Jakub take a look?
Comment 2 Jakub Jelinek 2019-06-24 11:24:23 UTC
Created attachment 46514 [details]
gcc10-pr90954.patch

Untested fix.
Comment 3 Jakub Jelinek 2019-06-25 07:01:06 UTC
Author: jakub
Date: Tue Jun 25 07:00:34 2019
New Revision: 272635

URL: https://gcc.gnu.org/viewcvs?rev=272635&root=gcc&view=rev
Log:
	PR sanitizer/90954
	* c-omp.c (c_finish_omp_atomic): Allow tree_invariant_p in addition
	to SAVE_EXPR in first operand of a COMPOUND_EXPR.

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

Added:
    trunk/gcc/testsuite/c-c++-common/gomp/pr90954.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-omp.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jakub Jelinek 2019-06-28 22:56:00 UTC
Author: jakub
Date: Fri Jun 28 22:55:29 2019
New Revision: 272802

URL: https://gcc.gnu.org/viewcvs?rev=272802&root=gcc&view=rev
Log:
	Backported from mainline
	2019-06-25  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/90954
	* c-omp.c (c_finish_omp_atomic): Allow tree_invariant_p in addition
	to SAVE_EXPR in first operand of a COMPOUND_EXPR.

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

Added:
    branches/gcc-9-branch/gcc/testsuite/c-c++-common/gomp/pr90954.c
Modified:
    branches/gcc-9-branch/gcc/c-family/ChangeLog
    branches/gcc-9-branch/gcc/c-family/c-omp.c
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2019-08-29 15:04:02 UTC
Author: jakub
Date: Thu Aug 29 15:03:31 2019
New Revision: 275043

URL: https://gcc.gnu.org/viewcvs?rev=275043&root=gcc&view=rev
Log:
	Backported from mainline
	2019-06-25  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/90954
	* c-omp.c (c_finish_omp_atomic): Allow tree_invariant_p in addition
	to SAVE_EXPR in first operand of a COMPOUND_EXPR.

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

Added:
    branches/gcc-8-branch/gcc/testsuite/c-c++-common/gomp/pr90954.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/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2019-08-30 12:48:00 UTC
Author: jakub
Date: Fri Aug 30 12:47:28 2019
New Revision: 275161

URL: https://gcc.gnu.org/viewcvs?rev=275161&root=gcc&view=rev
Log:
	Backported from mainline
	2019-06-25  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/90954
	* c-omp.c (c_finish_omp_atomic): Allow tree_invariant_p in addition
	to SAVE_EXPR in first operand of a COMPOUND_EXPR.

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

Added:
    branches/gcc-7-branch/gcc/testsuite/c-c++-common/gomp/pr90954.c
Modified:
    branches/gcc-7-branch/gcc/c-family/ChangeLog
    branches/gcc-7-branch/gcc/c-family/c-omp.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2019-08-30 13:28:24 UTC
Fixed for 7.5.