leaningtech / cheerp-meta

Cheerp - a C/C++ compiler for Web applications - compiles to WebAssembly and JavaScript
https://labs.leaningtech.com/cheerp
Other
1.02k stars 50 forks source link

Compiler warnings when building "cheerp" #149

Open mingodad opened 1 year ago

mingodad commented 1 year ago

After getting a working build script that works (see here https://github.com/leaningtech/cheerp-meta/issues/147 ) I did an aggregation of all compiler warnings from building cheerp-latest see the results bellow:

Total unique warnings type count => 23
count   type
352 [-Wdeprecated-declarations]
220 [-Wunused-but-set-variable]
169 [-Wcheerp-maybe-slow]
90  [-Wunknown-attributes]
68  [-Wsign-compare]
60  [-Wshift-count-overflow]
52  [-Wcheerp-unsafe]
33  [-Wreorder-ctor]
25  [-Wunused-variable]
17  [-Wsign-conversion]
16  [-Wundefined-inline]
14  [-Wunused-parameter]
8   [-Wunused-private-field]
8   [-Wignored-attributes]
8   [-Wunused-function]
6   [-Winvalid-noreturn]
2   [-Wunused-const-variable]
2   [-Wc++98-compat-extra-semi]
2   [-Wmisleading-indentation]
2   [-Wundefined-internal]
1   [-Wimplicit-fallthrough]
1   [-Wunused-lambda-capture]
1   [-Wmacro-redefined]

Total unique files count => 68
count   file
260 /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/Utility.h
181 /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__functional/hash.h
104 /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/Registerize.h
90  /tmp/cheerp-latest/cheerp-libs/system/wasi_shim.cpp
66  /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/LinearMemoryHelper.h
61  /tmp/cheerp-latest/cheerp-compiler/build_runtimes_wasm/include/c++/v1/__functional/hash.h
52  /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/PointerAnalyzer.h
30  /tmp/cheerp-latest/cheerp-compiler/libcxx/src/locale.cpp
29  /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/PointerAnalyzer.cpp
25  /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/InvokeWrapping.h
24  /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__algorithm/shuffle.h
23  /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/cxa_cheerp.cpp
22  /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/CheerpWriter.cpp
14  /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/private_typeinfo.cpp
12  /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__threading_support
12  /tmp/cheerp-latest/cheerp-compiler/build_runtimes_wasm/include/c++/v1/__threading_support
12  /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__format/formatter_pointer.h
9   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/SIMDLowering.cpp
8   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/TypeOptimizer.cpp
8   /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__memory/shared_ptr.h
8   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/CheerpWasmWriter.cpp
7   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/fallback_malloc.cpp
6   /tmp/cheerp-latest/cheerp-compiler/libcxx/src/include/ryu/common.h
6   /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/string
6   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/cxa_aux_runtime.cpp
5   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/PreExecute.cpp
5   /tmp/cheerp-latest/cheerp-compiler/clang/lib/CodeGen/CGExprScalar.cpp
4   /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/ios
4   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/cxa_guard_impl.h
3   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/cxa_demangle.cpp
3   /tmp/cheerp-latest/cheerp-compiler/clang/lib/CodeGen/CGExprConstant.cpp
3   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/Scalar/SROA.cpp
3   /tmp/cheerp-latest/cheerp-compiler/clang/lib/CodeGen/CGVTables.cpp
3   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/demangle/ItaniumDemangle.h
3   /tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/TypeOptimizer.h
3   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/JSInterop.cpp
2   /tmp/cheerp-latest/cheerp-compiler/libcxx/src/mutex_destructor.cpp
2   /tmp/cheerp-latest/cheerp-compiler/clang/lib/AST/VTableBuilder.cpp
2   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/abort_message.cpp
2   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/NativeRewriter.cpp
2   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/GlobalDepsAnalyzer.cpp
2   /tmp/cheerp-latest/cheerp-compiler/libcxx/src/condition_variable_destructor.cpp
2   /tmp/cheerp-latest/cheerp-compiler/libcxx/src/iostream.cpp
2   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/IdenticalCodeFolding.cpp
2   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/Registerize.cpp
2   /tmp/cheerp-latest/cheerp-compiler/libcxxabi/src/cxa_vector.cpp
2   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/PointerPasses.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/AllocaMerging.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/Scalar/JumpThreading.cpp
1   /tmp/cheerp-latest/cheerp-compiler/clang/lib/Sema/SemaExpr.cpp
1   /tmp/cheerp-latest/cheerp-compiler/libcxx/src/memory.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/Opcodes.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/StructMemFuncLowering.cpp
1   /tmp/cheerp-latest/cheerp-compiler/clang/lib/Basic/Targets/WebAssembly.cpp
1   /tmp/cheerp-latest/cheerp-compiler/clang/lib/CodeGen/CGClass.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
1   /tmp/cheerp-latest/cheerp-compiler/clang/lib/CodeGen/ItaniumCXXABI.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpWriter/CFGStackifier.cpp
1   /tmp/cheerp-latest/cheerp-libs/system/common.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/SinkGenerator.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1   /tmp/cheerp-latest/cheerp-compiler/build_runtimes_wasm/include/c++/v1/__random/random_device.h
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/InvokeWrapping.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/Utility.cpp
1   /tmp/cheerp-latest/cheerp-compiler/build_runtimes_genericjs/include/c++/v1/__random/random_device.h
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/Transforms/Scalar/GVN.cpp
1   /tmp/cheerp-latest/cheerp-compiler/llvm/lib/CheerpUtils/LinearMemoryHelper.cpp

Total unique warnings count =>  67  
Total warnings count => 1157
count   warning
352 warning: 'getPointerElementType' is deprecated: Deprecated without replacement, see https://llvm.org/docs/OpaquePointers.html for context and migration instructions [-Wdeprecated-declarations]
164 warning: variable 'modulePtr' set but not used [-Wunused-but-set-variable]
129 warning: Cheerp: Unions are less efficient than on native targets [-Wcheerp-maybe-slow]
62  warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
60  warning: shift count >= width of type [-Wshift-count-overflow]
52  warning: Cheerp: Using values cast to unrelated types is undefined behaviour unless the destination type is the actual type of the value [-Wcheerp-unsafe]
52  warning: variable 'C' set but not used [-Wunused-but-set-variable]
45  warning: unknown attribute '__import_name__' ignored [-Wunknown-attributes]
45  warning: unknown attribute '__import_module__' ignored [-Wunknown-attributes]
40  warning: Cheerp: Casting genericjs pointers to integers may be slow. [-Wcheerp-maybe-slow]
33  warning: field 'functionTypeIndices' will be initialized after field 'maxFunctionId' [-Wreorder-ctor]
8   warning: inline function 'std::__libcpp_thread_id_equal' is not defined [-Wundefined-inline]
8   warning: '__stdcall' calling convention is not supported for this target [-Wignored-attributes]
8   warning: inline function 'std::__libcpp_thread_id_less' is not defined [-Wundefined-inline]
7   warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned int') to 'int' [-Wsign-conversion]
6   warning: function declared 'noreturn' should not return [-Winvalid-noreturn]
5   warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned int') [-Wsign-conversion]
4   warning: unused parameter 'adjustedPtr' [-Wunused-parameter]
4   warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
4   warning: unused parameter 'deref' [-Wunused-parameter]
3   warning: comparison of integers of different signs: 'size_type' (aka 'unsigned int') and 'int32_t' (aka 'int') [-Wsign-compare]
3   warning: unused variable 'it' [-Wunused-variable]
3   warning: comparison of integers of different signs: 'int32_t' (aka 'int') and 'size_type' (aka 'unsigned int') [-Wsign-compare]
2   warning: private field '__f_' is not used [-Wunused-private-field]
2   warning: unused function 'fallback_malloc' [-Wunused-function]
2   warning: unused variable 'UsableAllocSize' [-Wunused-const-variable]
2   warning: unused variable 'argType' [-Wunused-variable]
2   warning: unused variable 'opType' [-Wunused-variable]
2   warning: unused function 'is_fallback_ptr' [-Wunused-function]
2   warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-extra-semi]
2   warning: unused parameter 'thrown_type' [-Wunused-parameter]
2   warning: unused parameter 'format' [-Wunused-parameter]
2   warning: private field '__m_' is not used [-Wunused-private-field]
2   warning: unused function 'fallback_free' [-Wunused-function]
2   warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
2   warning: private field '__cv_' is not used [-Wunused-private-field]
2   warning: unused parameter 'static_downcast_offset' [-Wunused-parameter]
2   warning: unused function 'update_offset_to_base' [-Wunused-function]
2   warning: function '__cxxabiv1::(anonymous namespace)::__syscall_futex' has internal linkage but is not defined [-Wundefined-internal]
1   warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
1   warning: unused variable 'GType' [-Wunused-variable]
1   warning: unused variable 'bitWidth' [-Wunused-variable]
1   warning: unused variable 'phi' [-Wunused-variable]
1   warning: variable 'CurrentIsDirectBase' set but not used [-Wunused-but-set-variable]
1   warning: unused variable 'offset' [-Wunused-variable]
1   warning: unused variable 'I' [-Wunused-variable]
1   warning: unused variable 'iter' [-Wunused-variable]
1   warning: unused variable 'destVecType' [-Wunused-variable]
1   warning: variable 'ret' set but not used [-Wunused-but-set-variable]
1   warning: unused variable 'FType' [-Wunused-variable]
1   warning: unused variable 'intrinsic' [-Wunused-variable]
1   warning: unused variable 'BlockLikeTokens' [-Wunused-variable]
1   warning: unused variable 'inserted' [-Wunused-variable]
1   warning: private field 'LayoutClass' is not used [-Wunused-private-field]
1   warning: unused variable 'kind' [-Wunused-variable]
1   warning: variable 'phiEdgesAdded' set but not used [-Wunused-but-set-variable]
1   warning: 'LIBBUILTIN' macro redefined [-Wmacro-redefined]
1   warning: unused variable 'DL' [-Wunused-variable]
1   warning: unused variable 't' [-Wunused-variable]
1   warning: lambda capture 'performPtrIntConversions' is not used [-Wunused-lambda-capture]
1   warning: unused variable 'oldTy' [-Wunused-variable]
1   warning: implicit conversion changes signedness: 'unsigned int' to 'int' [-Wsign-conversion]
1   warning: unused variable 'paramType' [-Wunused-variable]
1   warning: private field 'AddressPointIndex' is not used [-Wunused-private-field]
1   warning: variable 'end' set but not used [-Wunused-but-set-variable]
1   warning: unused variable 'srcVecType' [-Wunused-variable]
1   warning: unused variable 'num' [-Wunused-variable]

Using this squilu (https://github.com/mingodad/squilu) script that uses Lua patterns (https://www.lua.org/manual/5.4/manual.html#6.4.1) :

auto fname = "/tmp/cheerp-latest/build.log";
auto txt = readfile(fname);

auto warnings_list = {};
auto warnings_count = 0;
auto warnings_types_list = {};
auto files_list = {};

txt.gmatch(
    ///tmp/cheerp-latest/cheerp-compiler/llvm/include/llvm/Cheerp/Utility.h:424:30: warning: 'getPointerElementType' is deprecated: Deprecated without replacement, see https://llvm.org/docs/OpaquePointers.html for context and migration instructions [-Wdeprecated-declarations]
    "\n([^\n]-):%d+:%d+: (warning:[^\n]+)",
    function(fname, warn) {
        table_incnum(warnings_list, warn, 1, true);
        ++warnings_count;
        auto warn_type = warn.match("%b[]");
        table_incnum(warnings_types_list, warn_type, 1, true);
        table_incnum(files_list, fname, 1, true);
        return true;
    }
);

auto ary = table_toarray(warnings_types_list);
ary.sort(@(a,b) b[1] <=> a[1]);

print("Total unique warnings type count =>", ary.len());
print("count\ttype");
foreach(elm in ary) print(elm[1], elm[0]);

ary = table_toarray(files_list);
ary.sort(@(a,b) b[1] <=> a[1]);

print("\n\nTotal unique files count =>", ary.len());
print("count\tfile");
foreach(elm in ary) print(elm[1], elm[0]);

ary = table_toarray(warnings_list);
ary.sort(@(a,b) b[1] <=> a[1]);

print("\n\nTotal unique warnings count =>", ary.len(), "\nTotal warnings count =>", warnings_count);
print("count\twarning");
foreach(elm in ary) print(elm[1], elm[0]);
mingodad commented 1 year ago

And that number would be a bit bigger without this command line parameters:

-Wno-pointer-to-int-cast -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith -Werror=int-conversion -Werror=incompatible-pointer-types -Qunused-arguments -Waddress -Warray-bounds -Wchar-subscripts -Wduplicate-decl-specifier -Winit-self -Wreturn-type -Wsequence-point -Wstrict-aliasing -Wunused-function -Wunused-label -Wunused-variable -Wno-int-conversion