ridiculousfish / libdivide

Official git repository for libdivide: optimized integer division
http://libdivide.com
Other
1.1k stars 79 forks source link

libdivide.h:1691:59: error: ‘numers’ may be used uninitialized in this function #90

Closed useperl closed 2 years ago

useperl commented 2 years ago

Hello, when I try to build libdivide with gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) under Ubuntu 20.04, I get the following error:

...
[ 30%] Building CXX object CMakeFiles/benchmark.dir/test/benchmark.cpp.o
In file included from /home/hb/proj/libdivide/test/benchmark.h:24,
                 from /home/hb/proj/libdivide/test/benchmark.cpp:16:
/home/hb/proj/libdivide/libdivide.h: In function ‘uint64_t sum_quotients_vec(const random_numerators<IntT>&, const Divisor&) [with IntT = short unsigned int; Divisor = libdivide::divider<short unsigned int, libdivide::BRANCHFULL>]’:
/home/hb/proj/libdivide/libdivide.h:1691:59: error: ‘numers’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1691 |         pTarget[loop] = libdivide_##Algo##_do(pSource[loop], denom); \
      |                                                           ^
...

I just run cmake ., then make, and then get the error. (Running make -j instead of just make gives the same error). Am I doing anything wrong? What's the easiest way to fix or work around? I'm just trying to get a working benchmark binary. I tried building current master branch...

commit b785c76ea6cf3b85108324f12cd4d16f0e75563e (HEAD -> master, origin/master, origin/HEAD)
Author: Kim Walisch <kim.walisch@gmail.com>

    Delete CHANGELOG.md

... as well as release 5.0:

commit b322221677351ebb11f0a42fe9a9a2794da5bfe5 (tag: 5.0)
Author: ridiculousfish <corydoras@ridiculousfish.com>

    Stop passing multiple targets to cmake build

with the same error

adbancroft commented 2 years ago

I followed your steps & can reproduce. Only happens in Release configuration - cmake . -DCMAKE_BUILD_TYPE=Debug works.

adbancroft commented 2 years ago

Looks like GCC on x86 has some vector intrinsics that might be interfering. Or possibly alignment issues.

In the meantime cmake . -DLIBDIVIDE_SSE2=OFF -DLIBDIVIDE_AVX2=OFF -DLIBDIVIDE_AVX512=OFF -DLIBDIVIDE_NEON=OFF should work.