llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.55k stars 11.8k forks source link

valgrind error in llvm::APInt::setBits #83125

Open dcb314 opened 7 months ago

dcb314 commented 7 months ago

This C code:

int CoordType;
void Distance_TOR_3D() {
  if (CoordType != Distance_TOR_3D)
    Distance_TOR_3D();
}

does this with recent clang trunk:

$ valgrind -q --trace-children=yes /home/dcb38/llvm/results/bin/clang -c -O1 bug36.c
bug36.c:3:17: warning: comparison between pointer and integer ('int' and 'void (
*)()') [-Wpointer-integer-compare]
    3 |   if (CoordType != Distance_TOR_3D)
      |       ~~~~~~~~~ ^  ~~~~~~~~~~~~~~~
==1082850== Conditional jump or move depends on uninitialised value(s)
==1082850==    at 0xCBACA9: llvm::APInt::setBits(unsigned int, unsigned int) (in /home/dcb38/llvm/results.20240227/bin/clang-19)
==1082850==    by 0x1153296: computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (in /home/dcb38/llvm/results.20240227/bin/clang-19)
dcb314 commented 7 months ago

I managed to get -g1 into today's build, so here is more detail on the stack backtrace:

==1602893== Conditional jump or move depends on uninitialised value(s) ==1602893== at 0xCBBFE9: llvm::APInt::setBits(unsigned int, unsigned int) (APInt.h:1340) ==1602893== by 0x11547C6: setLowBits (APInt.h:1361) ==1602893== by 0x11547C6: computeKnownBits(llvm::Value const, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (ValueTracking.cpp:1878) ==1602893== by 0x1154A65: llvm::computeKnownBits(llvm::Value const, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (ValueTracking.cpp:161)

dcb314 commented 4 months ago

Months later and I see this

==1092216== Conditional jump or move depends on uninitialised value(s) ==1092216== at 0xC680D9: llvm::APInt::setBits(unsigned int, unsigned int) (APInt.h:1347) ==1092216== by 0x1128C70: setLowBits (APInt.h:1368) ==1092216== by 0x1128C70: computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (ValueTracking.cpp:2050)

from clang testsuite file ./CodeGen/debug-info-extern-callback.c

If the bugs don't get fixed, then there isn't much point me reporting them ;-|

JOE1994 commented 4 months ago

==1092216== Conditional jump or move depends on uninitialised value(s) ==1092216== at 0xC680D9: llvm::APInt::setBits(unsigned int, unsigned int) (APInt.h:1347) ==1092216== by 0x1128C70: setLowBits (APInt.h:1368) ==1092216== by 0x1128C70: computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (ValueTracking.cpp:2050)

from clang testsuite file ./CodeGen/debug-info-extern-callback.c

With clang trunk at 92a870888c2d19f0004d2d0bc90730559c6bf0f4, I ran gdb --args clang -c clang/test/CodeGen/debug-info-extern-callback.c and break ValueTracking.cpp:2050. I'm unable to hit the breakpoint in gdb...

@dcb314 Could you try hitting the same breakpoint with a debugger on your end? Could you also share 1) which clang commit hash you used and 2) what arguments were fed to clang in your testing today?

dcb314 commented 4 months ago

This is embarrassing:

test $ for i in ~/llvm/results.20240*/bin/clang

do echo $i ~/valgrind/results/bin/valgrind -q --trace-children=yes $i -c -g -O3 -march=zen3 -Wall ./CodeGen/debug-info-extern-callback.c done /home/dcb40b/llvm/results.20240519/bin/clang /home/dcb40b/llvm/results.20240520/bin/clang /home/dcb40b/llvm/results.20240521/bin/clang /home/dcb40b/llvm/results.20240522/bin/clang /home/dcb40b/llvm/results.20240523/bin/clang /home/dcb40b/llvm/results.20240524/bin/clang /home/dcb40b/llvm/results.20240525/bin/clang /home/dcb40b/llvm/results.20240527/bin/clang /home/dcb40b/llvm/results.20240528/bin/clang /home/dcb40b/llvm/results.20240529/bin/clang /home/dcb40b/llvm/results.20240530/bin/clang /home/dcb40b/llvm/results.20240531/bin/clang /home/dcb40b/llvm/results.20240603/bin/clang /home/dcb40b/llvm/results.20240605/bin/clang /home/dcb40b/llvm/results.20240606/bin/clang test $

Cannot reproduce today. Sorry.