hyperscan
hyperscan copied to clipboard
clang-13 `-Wunused-but-set-variable` causes compilation failure
When compiling the project under macOS with the latest command line tools version 13.3.0.0.1.1645755326
, which uses clang version Apple clang version 13.1.6 (clang-1316.0.21.2)
, the project fails to be built, reporting error like:
FAILED: CMakeFiles/hs_compile.dir/src/nfa/mcsheng_compile.cpp.o
/Library/Developer/CommandLineTools/usr/bin/c++ -I/Users/ss/dev/tools/vcpkg/buildtrees/chimera/x64-osx-dbg -I/Users/ss/dev/tools/vcpkg/buildtrees/chimera/src/28a3d3326e-133ce01161.clean -I/Users/ss/dev/tools/vcpkg/buildtrees/chimera/src/28a3d3326e-133ce01161.clean/src -isystem /Users/ss/dev/tools/vcpkg/buildtrees/chimera/src/28a3d3326e-133ce01161.clean/include -isystem /Users/ss/dev/tools/vcpkg/installed/x64-osx/include -fPIC -march=native -mtune=native -O2 -std=c++11 -Wall -Wextra -Wshadow -Wswitch -Wreturn-type -Wcast-qual -Wno-deprecated -Wnon-virtual-dtor -fno-strict-aliasing -Werror -fno-omit-frame-pointer -Wvla -Wpointer-arith -Wno-self-assign -Wno-unused-const-variable -Wno-ignored-attributes -Wno-redundant-move -Wweak-vtables -Wmissing-declarations -g -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -MD -MT CMakeFiles/hs_compile.dir/src/nfa/mcsheng_compile.cpp.o -MF CMakeFiles/hs_compile.dir/src/nfa/mcsheng_compile.cpp.o.d -o CMakeFiles/hs_compile.dir/src/nfa/mcsheng_compile.cpp.o -c /Users/ss/dev/tools/vcpkg/buildtrees/chimera/src/28a3d3326e-133ce01161.clean/src/nfa/mcsheng_compile.cpp
/Users/ss/dev/tools/vcpkg/buildtrees/chimera/src/28a3d3326e-133ce01161.clean/src/nfa/mcsheng_compile.cpp:1170:13: error: variable 'total_daddy' set but not used [-Werror,-Wunused-but-set-variable]
u16 total_daddy = 0;
^
1 error generated.
And it is caused by clang-13 introducing -Wunused-but-set-variable
by default, which makes compilation fails.
Similar with this issue
I am running into the problem as well when building the latest envoy proxy using clang-13. However, total_daddy is used:
if (info.impl_alpha_size > 16) {
u16 total_daddy = 0;
for (u32 i = 0; i < info.size(); i++) {
find_better_daddy(info, i,
is_cyclic_near(info.raw, info.raw.start_anchored),
grey);
total_daddy += info.extra[i].daddytaken;
}
DEBUG_PRINTF("daddy %hu/%zu states=%zu alpha=%hu\n", total_daddy,
info.size() * info.impl_alpha_size, info.size(),
info.impl_alpha_size);
}
So, you cannot just remove it. Maybe the compiler is smart enough to tell that when DEBUG_PRINTF is not define, even it adds to total_daddy but it never really get used? That seems to be either a bug in clang-13 or this aggressive behavior should not be default ever.
Exact version of clang: Ubuntu clang version 13.0.1-++20220120110924+75e33f71c2da-1~exp1~20220120231001.58
Pleases refer to latest develop branch to see if your issues is solved. Some clang warnings are silenced at f69696999e8d22e9f9ead12e8384e8f357fe3854