emscripten-core / emscripten-core/emscripten
ICE when function return type is std::true_type
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
This crash has first been detected during search for workaround for [this bug](https://github.com/emscripten-core/emscripten/issues/15432#issuecomment-961339394) (link points to comment where I first found the crash).
I've managed to isolate the problem to having function that returns the `std::true_type`. The simplest repro case is
```c++
#include
std::true_type doOrDont();
void process()
{
[[ maybe_unused ]] auto const did{ doOrDont() };
}
```
However, if I simply put the code above through `em++`, it works correctly, but fortunately, I've been able to scale down the crash reproducer from our proprietary codebase to the version that does not reveal any of our IP, yet still reproduces the crash. The reproducer is attached in this zip file:
[emscripten-crash.zip](https://github.com/emscripten-core/emscripten/files/7490916/emscripten-crash.zip)
Note that with emscripten 2.0.31 this works. You can easily check that by updating the `sh` file in provided zip to point to clang binary from the 2.0.31 distribution - you just need to remove the `-clear-ast-before-backend` flag which is not supported by the clang from emscripten 2.0.31. I've also tested removing this flag in 2.0.34, but it didn't help.
The crash trace is:
```
Assertion failed: ((D.hasGlobalStorage() || (D.hasLocalStorage() && CGF.getContext().getLangOpts().OpenCLCPlusPlus)) && "VarDecl must have global or local (in the case of OpenCL) storage!"), function EmitDeclInit, file /opt/s/w/ir/cache/builder/emscripten-releases/llvm-project/clang/lib/CodeGen/CGDeclCXX.cpp, line 33.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /Users/dodo/.conan/data/emsdk_installer/2.0.34/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/bin/clang-14 -cc1 -triple wasm32-unknown-emscripten -emit-llvm-bc -flto=full -flto-unit -disable-free -clear-ast-before-backend -main-file-name biased_matmul.cpp -mrelocation-model static -fmerge-all-constants -fenable-matrix -mllvm -enable-matrix -mframe-pointer=none -fstrict-enums -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -target-cpu generic -target-feature +mutable-globals -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -target-linker-version 14.0.0 -ffunction-sections -fcoverage-compilation-dir=/Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.34/release -sys-header-deps -D __EMSCRIPTEN_major__=2 -D __EMSCRIPTEN_minor__=0 -D __EMSCRIPTEN_tiny__=34 -D _LIBCPP_ABI_VERSION=2 -D ALL_KEYS -D ALL_SYMMETRIC_KEYS -D BOOST_NO_EXCEPTIONS -D BOOST_NO_RTTI -D EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS=16 -D EIGEN_CMAKE_INCLUDED -D EIGEN_DEFAULT_DENSE_INDEX_TYPE=std::int32_t -D EIGEN_DEFAULT_TO_ROW_MAJOR -D EIGEN_FAST_MATH -D EIGEN_MAX_STATIC_ALIGN_BYTES=16 -D EIGEN_MPL2_ONLY -D EIGEN_NO_AUTOMATIC_RESIZING -D EIGEN_STACK_ALLOCATION_LIMIT=0 -D ENABLE_RESULT_SIGNATURE -D LOG_LEVEL=0 -D MB_ACCELERATE_Multithreaded=2 -D MB_ACCELERATE_Off=0 -D MB_ACCELERATE_Singlethreaded=1 -D MB_NN_API_BUILD=1 -D MB_NN_DLL=1 -D MB_NN_XNNPACK=1 -D MB_NOEXCEPT_EXCEPT_BADALLOC=TNUN_NOEXCEPT_EXCEPT_BADALLOC -D MB_USE_ACCELERATE=MB_ACCELERATE_Off -D NN_ALIGNED_MODELS -D NN_GRAPH_PER_LAYER_DEBUGGING=1 -D NN_MODEL_DEFAULT_ALIGNMENT=8 -D NN_MODEL_EXTENSION=.strop -D NN_SINGLETHREADED_ALLOCATOR=1 -D NN_USE_PROTECTION=1 -D NN_WINOGRAD=1 -D PRODUCT_ID=MB::Protection::Product::MicroBlinkCore -D PROTECT -D TNUN_MALLOC_OVERCOMMIT=TNUN_OVERCOMMIT_Partial -D TNUN_NOEXCEPT_EXCEPT_BADALLOC= -D TNUN_OVERCOMMIT_Disabled=0 -D TNUN_OVERCOMMIT_Full=2 -D TNUN_OVERCOMMIT_Partial=1 -D U_EXPORT= -D uECC_SUPPORTS_secp160r1=0 -D uECC_SUPPORTS_secp192r1=0 -D uECC_SUPPORTS_secp224r1=0 -D uECC_SUPPORTS_secp256r1=0 -D uECC_SUPPORTS_secp521r1=0 -D NDEBUG -D NDEBUG -O3 -Werror=implicit-function-declaration -Wheader-guard -Wall -Wextra -Wstrict-aliasing -Wdocumentation -Wno-error=deprecated-declarations -Wno-error=#warnings -Wno-error=unknown-attributes -Wno-unused-command-line-argument -Wno-sign-compare -std=gnu++20 -fdeprecated-macro -fdebug-compilation-dir=/Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.34/release -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -funroll-loops -fno-rtti -fgnuc-version=4.2.1 -fno-threadsafe-statics -fignore-exceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -iwithsysroot/include/SDL -iwithsysroot/include/compat -x c++ biased_matmul-68e0c5.cpp
1. parser at end of file
2. /Users/dodo/.conan/data/emsdk_installer/2.0.34/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/.emscripten_cache/sysroot/include/c++/v1/span:559:6: LLVM IR generation of declaration 'biased_matmul_st_block'
3. /Users/dodo/.conan/data/emsdk_installer/2.0.34/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/.emscripten_cache/sysroot/include/c++/v1/span:559:6: Generating code for declaration 'biased_matmul_st_block'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 libLLVM.dylib 0x000000011408567b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1 libLLVM.dylib 0x0000000114084448 llvm::sys::RunSignalHandlers() + 248
2 libLLVM.dylib 0x0000000114085ce0 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007ff807aace2d _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000a52364 _sigtramp + 18446603370463122772
5 libsystem_c.dylib 0x00007ff8079e3d10 abort + 123
6 libsystem_c.dylib 0x00007ff8079e30be err + 0
7 libclang-cpp.dylib 0x000000010e43613a clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit(clang::VarDecl const&, llvm::Constant*, bool) + 3178
8 libclang-cpp.dylib 0x000000010e6bf5d3 (anonymous namespace)::ItaniumCXXABI::EmitGuardedInit(clang::CodeGen::CodeGenFunction&, clang::VarDecl const&, llvm::GlobalVariable*, bool) + 2563
9 libclang-cpp.dylib 0x000000010e42934d clang::CodeGen::CodeGenFunction::AddInitializerToStaticVarDecl(clang::VarDecl const&, llvm::GlobalVariable*) + 701
10 libclang-cpp.dylib 0x000000010e427bbf clang::CodeGen::CodeGenFunction::EmitStaticVarDecl(clang::VarDecl const&, llvm::GlobalValue::LinkageTypes) + 255
11 libclang-cpp.dylib 0x000000010e42acd7 clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) + 855
12 libclang-cpp.dylib 0x000000010e4278e5 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) + 293
13 libclang-cpp.dylib 0x000000010e4272f1 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) + 369
14 libclang-cpp.dylib 0x000000010e5b8d6b clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) + 155
15 libclang-cpp.dylib 0x000000010e5ad652 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef) + 594
16 libclang-cpp.dylib 0x000000010e5ac564 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef) + 164
17 libclang-cpp.dylib 0x000000010e5b9e40 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) + 512
18 libclang-cpp.dylib 0x000000010e61d838 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 1752
19 libclang-cpp.dylib 0x000000010e63cabe clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 446
20 libclang-cpp.dylib 0x000000010e6353ff clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 479
21 libclang-cpp.dylib 0x000000010e639722 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) + 1234
22 libclang-cpp.dylib 0x000000010e64106b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 2603
23 libclang-cpp.dylib 0x000000010e6e075f (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 159
24 libclang-cpp.dylib 0x000000010e60f595 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 181
25 libclang-cpp.dylib 0x000000010d20f127 clang::ParseAST(clang::Sema&, bool, bool) + 775
26 libclang-cpp.dylib 0x000000010ec20953 clang::FrontendAction::Execute() + 99
27 libclang-cpp.dylib 0x000000010eb9b1ef clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 831
28 libclang-cpp.dylib 0x000000010eca53fc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 540
29 clang-14 0x0000000106ae017e cc1_main(llvm::ArrayRef, char const*, void*) + 1438
30 clang-14 0x0000000106addddb ExecuteCC1Tool(llvm::SmallVectorImpl&) + 283
31 clang-14 0x0000000106addafc main + 12668
32 dyld 0x0000000109b6a4fe start + 462
33 dyld 000000000000000000 start + 18446744069251620048
34 clang-14 0x0000000106ad6000 __dso_handle + 0
./biased_matmul-68e0c5.sh: line 4: 39329 Abort trap: 6 "/Users/dodo/.conan/data/emsdk_installer/2.0.34/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/bin/clang-14" "-cc1" "-triple" "wasm32-unknown-emscripten" "-emit-llvm-bc" "-flto=full" "-flto-unit" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "biased_matmul.cpp" "-mrelocation-model" "static" "-fmerge-all-constants" "-fenable-matrix" "-mllvm" "-enable-matrix" "-mframe-pointer=none" "-fstrict-enums" "-menable-no-infs" "-menable-no-nans" "-menable-unsafe-fp-math" "-fno-signed-zeros" "-mreassociate" "-freciprocal-math" "-ffp-contract=fast" "-fno-rounding-math" "-ffast-math" "-ffinite-math-only" "-mconstructor-aliases" "-target-cpu" "generic" "-target-feature" "+mutable-globals" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-target-linker-version" "14.0.0" "-ffunction-sections" "-fcoverage-compilation-dir=/Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.34/release" "-sys-header-deps" "-D" "__EMSCRIPTEN_major__=2" "-D" "__EMSCRIPTEN_minor__=0" "-D" "__EMSCRIPTEN_tiny__=34" "-D" "_LIBCPP_ABI_VERSION=2" "-D" "ALL_KEYS" "-D" "ALL_SYMMETRIC_KEYS" "-D" "BOOST_NO_EXCEPTIONS" "-D" "BOOST_NO_RTTI" "-D" "EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS=16" "-D" "EIGEN_CMAKE_INCLUDED" "-D" "EIGEN_DEFAULT_DENSE_INDEX_TYPE=std::int32_t" "-D" "EIGEN_DEFAULT_TO_ROW_MAJOR" "-D" "EIGEN_FAST_MATH" "-D" "EIGEN_MAX_STATIC_ALIGN_BYTES=16" "-D" "EIGEN_MPL2_ONLY" "-D" "EIGEN_NO_AUTOMATIC_RESIZING" "-D" "EIGEN_STACK_ALLOCATION_LIMIT=0" "-D" "ENABLE_RESULT_SIGNATURE" "-D" "LOG_LEVEL=0" "-D" "MB_ACCELERATE_Multithreaded=2" "-D" "MB_ACCELERATE_Off=0" "-D" "MB_ACCELERATE_Singlethreaded=1" "-D" "MB_NN_API_BUILD=1" "-D" "MB_NN_DLL=1" "-D" "MB_NN_XNNPACK=1" "-D" "MB_NOEXCEPT_EXCEPT_BADALLOC=TNUN_NOEXCEPT_EXCEPT_BADALLOC" "-D" "MB_USE_ACCELERATE=MB_ACCELERATE_Off" "-D" "NN_ALIGNED_MODELS" "-D" "NN_GRAPH_PER_LAYER_DEBUGGING=1" "-D" "NN_MODEL_DEFAULT_ALIGNMENT=8" "-D" "NN_MODEL_EXTENSION=.strop" "-D" "NN_SINGLETHREADED_ALLOCATOR=1" "-D" "NN_USE_PROTECTION=1" "-D" "NN_WINOGRAD=1" "-D" "PRODUCT_ID=MB::Protection::Product::MicroBlinkCore" "-D" "PROTECT" "-D" "TNUN_MALLOC_OVERCOMMIT=TNUN_OVERCOMMIT_Partial" "-D" "TNUN_NOEXCEPT_EXCEPT_BADALLOC=" "-D" "TNUN_OVERCOMMIT_Disabled=0" "-D" "TNUN_OVERCOMMIT_Full=2" "-D" "TNUN_OVERCOMMIT_Partial=1" "-D" "U_EXPORT=" "-D" "uECC_SUPPORTS_secp160r1=0" "-D" "uECC_SUPPORTS_secp192r1=0" "-D" "uECC_SUPPORTS_secp224r1=0" "-D" "uECC_SUPPORTS_secp256r1=0" "-D" "uECC_SUPPORTS_secp521r1=0" "-D" "NDEBUG" "-D" "NDEBUG" "-O3" "-Werror=implicit-function-declaration" "-Wheader-guard" "-Wall" "-Wextra" "-Wstrict-aliasing" "-Wdocumentation" "-Wno-error=deprecated-declarations" "-Wno-error=#warnings" "-Wno-error=unknown-attributes" "-Wno-unused-command-line-argument" "-Wno-sign-compare" "-std=gnu++20" "-fdeprecated-macro" "-fdebug-compilation-dir=/Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.34/release" "-ferror-limit" "19" "-fvisibility" "hidden" "-fvisibility-inlines-hidden" "-funroll-loops" "-fno-rtti" "-fgnuc-version=4.2.1" "-fno-threadsafe-statics" "-fignore-exceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-iwithsysroot/include/SDL" "-iwithsysroot/include/compat" "-x" "c++" "biased_matmul-68e0c5.cpp"
```
Contributor guide
Assessment
This issue has not been assessed yet.