Skip to content

ubsan: jerryscript/jerry-core/vm/opcodes-ecma-bitwise.c:96:70: runtime error: left shift of negative value -1 #4701

Closed
@Cancelll

Description

@Cancelll
JerryScript revision

ccc1525

Build platform

Ubuntu 20.04.1 LTS (Linux 5.4.0-74-generic x86_64)

Build steps
readonly FLAGS=(
  "-g -O1 -fsanitize=address,undefined -fno-sanitize-recover=undefined,address"
)
cmake -D CMAKE_C_FLAGS="${FLAG}" -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX:PATH="${INSTALL_DIR}" "${SRC_FOLDER}"
make
make install
Test case
function f() {
    var x = (("-1.234" << 0));
    var y = 3.14;
    assertEq(true && x < y, true);
}
f();
Output
jerryscript/jerry-core/vm/opcodes-ecma-bitwise.c:96:70: runtime error: left shift of negative value -1
Expected behavior

According to C99 standard (6.5.7/4):

The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
zeros. If E1 has an unsigned type, the value of the result is E1 × 2 E2 , reduced modulo
one more than the maximum value representable in the result type. If E1 has a signed
type and nonnegative value, and E1 × 2 E2 is representable in the result type, then that is
the resulting value; otherwise, the behavior is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions