wabt icon indicating copy to clipboard operation
wabt copied to clipboard

C++ warnings while compiling wabt 1.0.19

Open steven-johnson opened this issue 5 years ago • 2 comments

We just upgraded from using 1.0.18 to 1.0.19; when builiding with GCC 10.2 on Linux, I get the following warnings that look concerning:

(only once:)

[79/3359] Building CXX object _deps/wabt-build/CMakeFiles/wabt.dir/src/binary-writer-spec.cc.o
In file included from _deps/wabt-src/src/binary-writer.h:20,
                 from _deps/wabt-src/src/binary-writer-spec.h:24,
                 from _deps/wabt-src/src/binary-writer-spec.cc:17:
_deps/wabt-src/src/common.h: In member function ‘void wabt::{anonymous}::BinaryWriterSpec::WriteConst(const wabt::Const&)’:
_deps/wabt-src/src/common.h:143:40: warning: array subscript 32 is above array bounds of ‘const uint8_t [16]’ {aka ‘const unsigned char [16]’} [-Warray-bounds]
  143 |     memcpy(&result, &v[lane * sizeof(T)], sizeof(result));
      |                      ~~~~~~~~~~~~~~~~~~^
_deps/wabt-src/src/common.h:154:11: note: while referencing ‘v128::v’
  154 |   uint8_t v[16];
      |           ^

(many times:)

_deps/wabt-src/src/stream.cc: In member function ‘void wabt::Stream::Writef(const char*, ...)’:
_deps/wabt-src/src/common.h:71:33: warning: argument to ‘alloca’ may be too large [-Walloca-larger-than=]
   71 |     buffer = static_cast<char*>(alloca(len + 1));                          \
      |                                 ^~~~~~
_deps/wabt-src/src/stream.cc:88:3: note: in expansion of macro ‘WABT_SNPRINTF_ALLOCA’
   88 |   WABT_SNPRINTF_ALLOCA(buffer, length, format);
      |   ^~~~~~~~~~~~~~~~~~~~

steven-johnson avatar Oct 27 '20 16:10 steven-johnson

Thanks, I'll take a look.

binji avatar Nov 02 '20 20:11 binji

I can see the ones about alloca() as well, but only when building on RHEL/CentOS 7 with gcc-10.2.1:

/opt/rh/devtoolset-10/root/usr/bin/c++  -DWASM_API_EXTERN="__attribute__((visibility(\"default\")))" -D__STDC_FORMAT_MACROS=1 -D__STDC_LIMIT_MACROS=1 -Dwasm_EXPORTS -I/builddir/build/BUILD/wabt-1.0.24 -I/builddir/build/BUILD/wabt-1.0.24/x86_64-redhat-linux-gnu -I/builddir/build/BUILD/wabt-1.0.24/third_party/wasm-c-api/include -I/builddir/build/BUILD/wabt-1.0.24/third_party/gtest/googletest -I/builddir/build/BUILD/wabt-1.0.24/third_party/gtest/googletest/include  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -std=c++11 -Wold-style-cast -fno-exceptions -fPIC -fvisibility=hidden   -Wall -Wextra -Wno-unused-parameter -Wpointer-arith -Wuninitialized -Wno-clobbered -Wno-old-style-cast -o CMakeFiles/wasm.dir/src/expr-visitor.cc.o -c /builddir/build/BUILD/wabt-1.0.24/src/expr-visitor.cc
In file included from /usr/include/stdlib.h:491,
                 from /opt/rh/devtoolset-10/root/usr/include/c++/10/cstdlib:75,
                 from /opt/rh/devtoolset-10/root/usr/include/c++/10/bits/stl_algo.h:59,
                 from /opt/rh/devtoolset-10/root/usr/include/c++/10/algorithm:62,
                 from /builddir/build/BUILD/wabt-1.0.24/src/common.h:20,
                 from /builddir/build/BUILD/wabt-1.0.24/src/binary-reader-ir.h:20,
                 from /builddir/build/BUILD/wabt-1.0.24/src/binary-reader-ir.cc:17:
/builddir/build/BUILD/wabt-1.0.24/src/binary-reader-ir.cc: In member function 'void wabt::{anonymous}::BinaryReaderIR::PrintError(const char*, ...)':
/builddir/build/BUILD/wabt-1.0.24/src/common.h:73:33: warning: argument to 'alloca' may be too large [-Walloca-larger-than=]
   73 |     buffer = static_cast<char*>(alloca(len + 1));                          \
      |                                 ^~~~~~
/builddir/build/BUILD/wabt-1.0.24/src/binary-reader-ir.cc:331:3: note: in expansion of macro 'WABT_SNPRINTF_ALLOCA'
  331 |   WABT_SNPRINTF_ALLOCA(buffer, length, format);
      |   ^~~~~~~~~~~~~~~~~~~~

... or on Fedora 33 with the same gcc:

/usr/bin/g++ -D__STDC_FORMAT_MACROS=1 -D__STDC_LIMIT_MACROS=1 -I/builddir/build/BUILD/wabt-1.0.20 -I/builddir/build/BUILD/wabt-1.0.20/x86_64-redhat-linux-gnu -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -std=c++11 -Wold-style-cast -fno-exceptions   -Wall -Wextra -Wno-unused-parameter -Wpointer-arith -g -Wuninitialized -Wno-clobbered -o CMakeFiles/wabt.dir/src/binary-writer-spec.cc.o -c /builddir/build/BUILD/wabt-1.0.20/src/binary-writer-spec.cc
In file included from /usr/include/stdlib.h:568,
                 from /usr/include/c++/10/cstdlib:75,
                 from /usr/include/c++/10/bits/stl_algo.h:59,
                 from /usr/include/c++/10/algorithm:62,
                 from /builddir/build/BUILD/wabt-1.0.20/src/common.h:20,
                 from /builddir/build/BUILD/wabt-1.0.20/src/binary.h:20,
                 from /builddir/build/BUILD/wabt-1.0.20/src/binary-reader.h:23,
                 from /builddir/build/BUILD/wabt-1.0.20/src/binary-reader.cc:17:
/builddir/build/BUILD/wabt-1.0.20/src/binary-reader.cc: In member function 'wabt::(anonymous namespace)::BinaryReader::PrintError(char const*, ...)':
/builddir/build/BUILD/wabt-1.0.20/src/common.h:71:33: warning: argument to 'alloca' may be too large [-Walloca-larger-than=]
   71 |     buffer = static_cast<char*>(alloca(len + 1));                          \
      |                                 ^~~~~~

They are gone with gcc-11 on Fedora (34 and later).

rathann avatar Aug 20 '21 13:08 rathann

These warnings seem to have been fixed, and WABT is now built (at least in CI) with -Werror (https://github.com/WebAssembly/wabt/pull/1185#issuecomment-1216990255).

keithw avatar Mar 15 '23 07:03 keithw