Skip to content

ubsan on arm64 detects invalid value Infinity (of type double) converted to int #75037

@RobertHenry6bev

Description

@RobertHenry6bev

Description

build dotnet/runtime using clang-14 -O3.
Use that runtime to execute cperfsim, viz.

See a ubsan runtime error complaining about conversion of infinithy to int32_t. yes, this is perhaps pedantic, since

BSAN_OPTIONS=halt_on_error=0,print_stacktrace=1,use_sigaltstack=false,suppressions=/home/robhenry/git-work-e2/robhenry-perf/dotnet_build/ubsan.supp \
        ASAN_OPTIONS=halt_on_error=0,alloc_dealloc_mismatch=0 \
        TSAN_OPTIONS=halt_on_error=0,force_seq_cst_atomics=1,verbosity=0,suppressions=/home/robhenry/git-work-e2/robhenry-perf/dotnet_build/tsan.supp \
        LSAN_OPTIONS=verbosity=1:log_threads=1 \
        \
        DOTNET_gcServer="1" \
        DOTNET_GCNoAffinitize=0 \
        DOTNET_Thread_UseAllCpuGroups=1 \
        DOTNET_GCCpuGroup=1 \
        DOTNET_GCHeapCount=4 \
        \
        gdb --args \
          ../dotnet_load/gcperfsim/bin/Release/net7.0/linux-arm64/GCPerfSim \
            -threadCount 3 -totalAllocGB 80.0 -totalLiveGB 20.0 -totalLiveGB 50.0 -sohSurvInterval 30 -lohSurvInterval 0 -pohSurvInterval 0 -sohSizeRange 100-4000 -lohSizeRange 102400-204800 -pohSizeRange 100-204800 -sohPinningInterval 50 -lohPinningInterval 0 -sohFinalizableInterval 0 -lohFinalizableInterval 0 -pohFinalizableInterval 0 -allocType reference -testKind time -lohAllocRatio 10 -pohAllocRatio 20 -totalMins 10  \

Here's the gdb backtrace: of the top 25 frames

0  __ubsan::ScopedReport::~ScopedReport (this=this@entry=0xffffffffc350, __in_chrg=<optimized out>)
    at ../../../../src/libsanitizer/ubsan/ubsan_diag.cpp:388
#1  0x0000fffff7948cdc in handleFloatCastOverflow (DataPtr=<optimized out>, From=9218868437227405312, Opts=...)
    at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:509
#2  0x0000fffff794b894 in __ubsan::__ubsan_handle_float_cast_overflow (Data=<optimized out>, From=<optimized out>)
    at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:513
#3  0x0000ff8105b941bc in emitter::canEncodeFloatImm8 (immDbl=<optimized out>, wbFPI=0x0)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/emitarm64.cpp:3162
#4  emitter::emitIns_valid_imm_for_fmov (immDbl=<optimized out>) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/emitarm64.cpp:2311
#5  0x0000ff8105bf23c4 in Compiler::gtSetEvalOrder (this=this@entry=0xaaaaaad97bd8, tree=tree@entry=0xaaaaaada56a8)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/gentree.cpp:4619
#6  0x0000ff8105bf1c74 in Compiler::gtSetEvalOrder (this=0xaaaaaad97bd8, tree=0xaaaaaada5748)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/gentree.cpp:5269
#7  0x0000ff8105bdf838 in Compiler::gtSetStmtInfo (this=0xaaaaaad97bd8, stmt=0xaaaaaada57e0)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.hpp:1362
#8  Compiler::fgFindOperOrder (this=0xaaaaaad97bd8) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/flowgraph.cpp:2941
#9  0x0000ff8105d964a0 in Phase::Run (this=0xffffffffc770) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/phase.cpp:61
#10 0x0000ff8105b71744 in DoPhase (_compiler=0xaaaaaad97bd8, _phase=PHASE_FIND_OPER_ORDER, _action=<optimized out>)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/phase.h:153
#11 Compiler::compCompile (this=this@entry=0xaaaaaad97bd8, methodCodePtr=methodCodePtr@entry=0xffffffffcc88, 
    methodCodeSize=methodCodeSize@entry=0xffffffffce04, compileFlags=compileFlags@entry=0xffffffffccb8)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:4723
#12 0x0000ff8105b74f90 in Compiler::compCompileHelper (this=this@entry=0xaaaaaad97bd8, classPtr=<optimized out>, classPtr@entry=0xffffa8034000, 
    compHnd=<optimized out>, methodInfo=<optimized out>, methodCodePtr=methodCodePtr@entry=0xffffffffcc88, 
    methodCodeSize=methodCodeSize@entry=0xffffffffce04, compileFlags=compileFlags@entry=0xffffffffccb8)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:6634
#13 0x0000ff8105b73f04 in Compiler::compCompile(CORINFO_MODULE_STRUCT_*, void**, unsigned int*, JitFlags*)::$_4::operator()(Compiler::compCompile(CORINFO_MODULE_STRUCT_*, void**, unsigned int*, JitFlags*)::__JITParam*) const (this=<optimized out>, __JITpParam=<optimized out>)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:5798
#14 Compiler::compCompile (this=this@entry=0xaaaaaad97bd8, classPtr=classPtr@entry=0xffffa8034000, methodCodePtr=methodCodePtr@entry=0xffffffffcc88, 
    methodCodeSize=methodCodeSize@entry=0xffffffffce04, compileFlags=0xffffffffccb8)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:5817
#15 0x0000ff8105b75d80 in jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::$_6::operator()(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::__JITParam*) const::{lambda(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::$_6::operator()(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::__JITParam*) const::__JITParam*)#1}::operator()(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::$_6::operator()(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::__JITParam*) const::__JITParam*) const (this=<optimized out>, 
    __JITpParam=<optimized out>) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:7280
#16 jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::$_6::operator()(jitNativeCode(CORINFO_METHOD_STRUCT_*, CORINFO_MODULE_STRUCT_*, ICorJitInfo*, CORINFO_METHOD_INFO*, void**, unsigned int*, JitFlags*, void*)::__JITParam*) const (__JITpParam=<optimized out>, this=<optimized out>) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:7305
#17 jitNativeCode (methodHnd=0xffffa9309950, classPtr=0xffffa8034000, compHnd=compHnd@entry=0xffffffffcf98, methodInfo=methodInfo@entry=0xffffffffce30, 
    methodCodePtr=methodCodePtr@entry=0xffffffffcc88, methodCodeSize=methodCodeSize@entry=0xffffffffce04, 
    compileFlags=compileFlags@entry=0xffffffffccb8, inlineInfoPtr=0x0) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/compiler.cpp:7307
#18 0x0000ff8105b81e68 in CILJit::compileMethod (this=<optimized out>, compHnd=0xffffffffcf98, methodInfo=0xffffffffce30, flags=<optimized out>, 
    entryAddress=0xffffffffce08, nativeSizeOfCode=0xffffffffce04) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/jit/ee_il_dll.cpp:261
#19 0x0000fffff69cc4e8 in invokeCompileMethodHelper (jitMgr=jitMgr@entry=0xaaaaaaafc950, comp=comp@entry=0xffffffffcf98, 
    info=info@entry=0xffffffffce30, jitFlags=..., nativeEntry=nativeEntry@entry=0xffffffffce08, nativeSizeOfCode=nativeSizeOfCode@entry=0xffffffffce04)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/jitinterface.cpp:12331
#20 0x0000fffff69cca38 in invokeCompileMethod (jitMgr=jitMgr@entry=0xaaaaaaafc950, comp=comp@entry=0xffffffffcf98, info=info@entry=0xffffffffce30, 
    jitFlags=..., nativeEntry=nativeEntry@entry=0xffffffffce08, nativeSizeOfCode=nativeSizeOfCode@entry=0xffffffffce04)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/jitinterface.cpp:12394
#21 0x0000fffff69cd670 in UnsafeJitFunction (config=config@entry=0xffffffffd580, ILHeader=ILHeader@entry=0xffffffffd190, flags=..., 
    pSizeOfCode=pSizeOfCode@entry=0xffffffffd324) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/jitinterface.cpp:12867
#22 0x0000fffff6a81ebc in MethodDesc::JitCompileCodeLocked (this=this@entry=0xffffa9309950, pConfig=pConfig@entry=0xffffffffd580, 
    pEntry=pEntry@entry=0xaaaaaacca720, pSizeOfCode=pSizeOfCode@entry=0xffffffffd324, pFlags=pFlags@entry=0xffffffffd328)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/prestub.cpp:952
#23 0x0000fffff6a818d4 in MethodDesc::JitCompileCodeLockedEventWrapper (this=this@entry=0xffffa9309950, pConfig=pConfig@entry=0xffffffffd580, 
    pEntry=0xaaaaaacca720) at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/prestub.cpp:823
#24 0x0000fffff6a80568 in MethodDesc::JitCompileCode (this=0xffffa9309950, pConfig=pConfig@entry=0xffffffffd580)
    at /mnt/robhenry/dotnet/clang11.a/runtime/src/coreclr/vm/prestub.cpp:763
#25 0x0000fffff6a7f5e0 in MethodDesc::PrepareILBasedCode (this=0xffffa9309950, pConfig=0xffffffffd580)

and the line of interest,; and values are:

3162	    int ival = (int)val;

Reproduction Steps

see above

Expected behavior

no runtime error

Actual behavior

ubsan runtime error

Regression?

No response

Known Workarounds

The code in canEncodeFloatImm8 looks a little sketchy. What does it do when presented with all the interesting kinds of floating point numbers (+Inf, -Inf, NaN, -0.0, +0.0 and denorms)?

Configuration

ARM64

Other information

No response

category:correctness
theme:floating-point
skill-level:intermediate
cost:medium
impact:small

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3Work that is nice to havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions