root icon indicating copy to clipboard operation
root copied to clipboard

Clang can't build ROOT anymore due to a new added diagnostic about undefined behavior

Open junaire opened this issue 3 years ago • 4 comments

  • [x] Checked for duplicates

When using clang trunk to build ROOT (main branch), it fails due to case value is not a constant expression

❯ clang --version
clang version 16.0.0 (https://github.com/llvm/llvm-project/ dde41c6c560b67165c7ac884815cd50fdce446f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jun/opt/clang/bin

cmake commands:

cmake -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
      -DCMAKE_C_COMPILER=clang            \
      -DCMAKE_CXX_COMPILER=clang++        \
      -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
      -GNinja ..

System info: I have tried Ubuntu 22 and WSL (Ubuntu 20) and got the same results.

Error message:

FAILED: io/io/CMakeFiles/RIO.dir/src/TGenCollectionStreamer.cxx.o 
/home/jun/opt/clang/bin/clang++  -I/home/jun/dev/root/io/io/inc -I/home/jun/dev/root/core/unix/inc -I/home/jun/dev/root/core/foundation/v7/inc -I/home/jun/dev/root/core/base/v7/inc -I/home/jun/dev/root/core/clingutils/inc -I/home/jun/dev/root/core/textinput/inc -I/home/jun/dev/root/core/thread/inc -I/home/jun/dev/root/core/zip/inc -I/home/jun/dev/root/core/rint/inc -I/home/jun/dev/root/core/clib/inc -I/home/jun/dev/root/core/meta/inc -I/home/jun/dev/root/core/gui/inc -I/home/jun/dev/root/core/cont/inc -I/home/jun/dev/root/core/foundation/inc -I/home/jun/dev/root/core/base/inc -I/home/jun/dev/root/Build/ginclude -I/home/jun/dev/root/core/clib/res -I/home/jun/dev/root/builtins -fcolor-diagnostics -std=c++14 -Wc++11-narrowing -Wsign-compare -Wsometimes-uninitialized -Wconditional-uninitialized -Wheader-guard -Warray-bounds -Wcomment -Wtautological-compare -Wstrncat-size -Wloop-analysis -Wbool-conversion -pipe  -Wall -W -Woverloaded-virtual -fsigned-char -pthread -g -fPIC -std=c++14 -MD -MT io/io/CMakeFiles/RIO.dir/src/TGenCollectionStreamer.cxx.o -MF io/io/CMakeFiles/RIO.dir/src/TGenCollectionStreamer.cxx.o.d -o io/io/CMakeFiles/RIO.dir/src/TGenCollectionStreamer.cxx.o -c /home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:392:18: error: case value is not a constant expression
            case EProperty(kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:392:18: note: integer value 536870912 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:394:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:394:18: note: integer value 4097 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:396:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:396:18: note: integer value 536875008 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:398:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISTSTRING | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:398:18: note: integer value 1073745921 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:445:18: error: case value is not a constant expression
            case EProperty(kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:445:18: note: integer value 536870912 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:450:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:450:18: note: integer value 4097 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:454:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:454:18: note: integer value 536875008 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:458:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISTSTRING | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:458:18: note: integer value 1073745921 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:867:18: error: case value is not a constant expression
            case EProperty(kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:867:18: note: integer value 536870912 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:870:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:870:18: note: integer value 4097 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:873:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISSTRING):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:873:18: note: integer value 536875008 is outside the valid range of values [0, 63] for this enumeration type
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:876:18: error: case value is not a constant expression
            case EProperty(kIsPointer | kBIT_ISTSTRING | kIsClass):
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jun/dev/root/io/io/src/TGenCollectionStreamer.cxx:876:18: note: integer value 1073745921 is outside the valid range of values [0, 63] for this enumeration type
12 errors generated.
[4730/6768] Building CXX object io/io/CMakeFiles/RIO.dir/src/TBufferJSON.cxx.o
ninja: build stopped: subcommand failed.

In addition, I found that the last time I build ROOT using clang trunk (before version 16), it was fine. So I guess there're some changes in the upstream that trigger this failure. However, I'm not sure if is it a false positive of clang diagnostic or a potential bug in ROOT we haven't discovered yet.

junaire avatar Aug 06 '22 05:08 junaire

Does it still build with an older version of Clang? Also, could you share your system's version of libc?

kgizdov avatar Aug 06 '22 12:08 kgizdov

Does it still build with an older version of Clang? Also, could you share your system's version of libc?

Yes, it builds at least in Clang 15. I've talked about this with @vgvassilev , and we believe it is possibly a clang bug. I'm bisecting it, need a little time ;)

junaire avatar Aug 06 '22 13:08 junaire

So now I can confirm that this breakage is introduced in https://reviews.llvm.org/D130058 . However, it seems that it's not a bug but a new diagnostic clang recently added. According to the description:

DR2338 clarified that it was undefined behavior to set the value outside the range of the enumerations values for an enum without a fixed underlying type.

We may want to fix this in our code as it's undefined behavior, but if not there's also an ongoing patch that downgrades this error to a warning: https://reviews.llvm.org/D131307

junaire avatar Aug 07 '22 07:08 junaire

Wow, you were fast in spotting this :smiley: I think there's a relatively simple fix, see https://github.com/root-project/root/pull/11148

hahnjo avatar Aug 08 '22 14:08 hahnjo

Should be fixed, but note that builtin_tbb is equally broken: https://github.com/root-project/root/issues/11179

hahnjo avatar Aug 12 '22 08:08 hahnjo