https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67798
Bug ID: 67798 Summary: Constant shift operation to the openmp unsigned loop variable gives a wrong result . Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: min.25.hy at gmail dot com Target Milestone: --- Constant shift operations to the openmp-unsigned loop variable gave a wrong result. ---[here is a source code]--- #include <cstdio> #include <omp.h> int main() { // output 4294967296 4294967296 instead of 0 4294967296 #pragma omp parallel for for (unsigned i = 1; i <= 1; ++i) { __uint128_t a = __uint128_t(i) << 32; printf("%llu %llu\n", (unsigned long long) (a >> 64), (unsigned long long) (a & 0xFFFFFFFFFFFFFFFFull)); } // output 0 4294967296 #pragma omp parallel for for (int i = 1; i <= 1; ++i) { __uint128_t a = __uint128_t(i) << 32; printf("%llu %llu\n", (unsigned long long) (a >> 64), (unsigned long long) (a & 0xFFFFFFFFFFFFFFFFull)); } return 0; } $ g++-5 -v Using built-in specs. COLLECT_GCC=g++-5 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/5.2.0/libexec/gcc/x86_64-apple-darwin11.4.2/5.2.0/lto-wrapper Target: x86_64-apple-darwin11.4.2 Configured with: ../configure --build=x86_64-apple-darwin11.4.2 --prefix=/usr/local/Cellar/gcc/5.2.0 --libdir=/usr/local/Cellar/gcc/5.2.0/lib/gcc/5 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-5 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 5.2.0' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib Thread model: posix gcc version 5.2.0 (Homebrew gcc 5.2.0) $ g++-5 -O3 -fopenmp shift.cpp $ ./a.out 4294967296 4294967296 0 4294967296