facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.41k stars 596 forks source link

Local debug and release build throws a type error #1340

Closed n0thhhing closed 1 month ago

n0thhhing commented 2 months ago

Bug Description

I've tried both release and debug

cmake -S hermes -B build_release -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build ./build_release
cmake -S hermes -B build -G Ninja
cmake --build ./build

and both throws this

[659/784] Building CXX object unittests...VMRuntimeTests.dir/Base64UtilTest.cpp.
FAILED: unittests/VMRuntime/CMakeFiles/HermesVMRuntimeTests.dir/Base64UtilTest.cpp.o
/data/data/com.termux/files/usr/bin/c++ -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_LANG_CXX11=1 -DHERMESVM_ALLOW_COMPRESSED_POINTERS -DHERMESVM_ALLOW_CONCURRENT_GC -DHERMESVM_ALLOW_CONTIGUOUS_HEAP -DHERMESVM_ALLOW_INLINE_ASM -DHERMESVM_GC_HADES -DHERMESVM_HEAP_SEGMENT_SIZE_KB=4096 -DHERMESVM_INDIRECT_THREADING -DHERMES_CHECK_NATIVE_STACK -DHERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32 -DHERMES_ENABLE_DEBUGGER -DHERMES_MEMORY_INSTRUMENTATION -DHERMES_RELEASE_VERSION=\"0.12.0\" -DUNIT_TEST -I/data/data/com.termux/files/home/native/hermes/external -I/data/data/com.termux/files/home/native/hermes/external/flowparser/include -I/data/data/com.termux/files/home/native/hermes/include -I/data/data/com.termux/files/home/native/build_release/include -I/data/data/com.termux/files/home/native/hermes/external/llvh/include -I/data/data/com.termux/files/home/native/hermes/external/llvh/gen/include -I/data/data/com.termux/files/home/native/build_release/external/llvh/include -I/data/data/com.termux/files/home/native/hermes/external/llvh/utils/unittest/googletest/include -I/data/data/com.termux/files/home/native/hermes/external/llvh/utils/unittest/googlemock/include -I/data/data/com.termux/files/home/native/hermes/public/hermes/Public/../.. -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wno-deprecated-copy -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -ffp-contract=on -Wno-range-loop-analysis -ffunction-sections -fdata-sections -faddrsig -fvisibility=hidden -Wno-sign-compare -O3 -DNDEBUG -std=c++17  -fno-exceptions -fno-rtti -MD -MT unittests/VMRuntime/CMakeFiles/HermesVMRuntimeTests.dir/Base64UtilTest.cpp.o -MF unittests/VMRuntime/CMakeFiles/HermesVMRuntimeTests.dir/Base64UtilTest.cpp.o.d -o unittests/VMRuntime/CMakeFiles/HermesVMRuntimeTests.dir/Base64UtilTest.cpp.o -c /data/data/com.termux/files/home/native/hermes/unittests/VMRuntime/Base64UtilTest.cpp
/data/data/com.termux/files/home/native/hermes/unittests/VMRuntime/Base64UtilTest.cpp:151:53: error: constant expression evaluates to -15 which cannot be narrowed to type 'char' [-Wc++11-narrowing]
  151 |   std::array<char, 5> hasNegative = {'A', 'b', 'c', -15, '\0'};
      |                                                     ^~~
/data/data/com.termux/files/home/native/hermes/unittests/VMRuntime/Base64UtilTest.cpp:151:53: note: insert an explicit cast to silence this issue
  151 |   std::array<char, 5> hasNegative = {'A', 'b', 'c', -15, '\0'};
      |                                                     ^~~
      |                                                     static_cast<char>( )
1 error generated.
[663/784] Building CXX object unittests...VMRuntimeTests.dir/CallResultTest.cpp.
[667/784] Building CXX object unittests...ests.dir/CodeCoverageProfilerTest.cpp.
ninja: build stopped: subcommand failed.

I have all dependencies installed

Hermes git revision (if applicable):latest? React Native version:local build(not react because the pre builds are not compatible with termux) OS: arm64-v8a termux

Steps To Reproduce

Followed the release and debug build steps

n0thhhing commented 2 months ago

Seems like editing the line to this fixes the issue

std::array<char, 5> hasNegative = {'A', 'b', 'c', static_cast<char>(-15), '\0'};
tmikov commented 2 months ago

This only happens on platforms where char is unsigned (i.e. arm64 Linux). We have a fix in the Static Hermes branch that will be ported here: https://github.com/facebook/hermes/commit/36a3d414f49a5d7b8a8bf315978b364974a15d31

tmikov commented 1 month ago

Fixed in https://github.com/facebook/hermes/commit/d77f1b6ada427e58f293cc61c30288228aaf0574