poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU poke 2.0.92 with ubsan


From: Bruno Haible
Subject: Re: GNU poke 2.0.92 with ubsan
Date: Mon, 07 Feb 2022 02:46:52 +0100

Mohammad-Reza Nabipoor wrote:
> You have to disable no-threading dispatch.

Indeed; thanks. Configuring with
  --disable-shared --disable-dispatch-no-threading
and setting the environment variable
  export UBSAN_OPTIONS="print_stacktrace=1"
I get more reasonable results:

$ ./run poke/poke
pvm-val.c:63:10: runtime error: left shift of 4294967295 by 32 places cannot be 
represented in type 'long int'
    #0 0x608421 in pvm_make_int /tmp/poke-2.0.92/libpoke/pvm-val.c:63
    #1 0x5eea7a in pkl_gen_ps_integer /tmp/poke-2.0.92/libpoke/pkl-gen.c:2103
    #2 0x472343 in pkl_call_node_handlers 
/tmp/poke-2.0.92/libpoke/pkl-pass.c:189
    #3 0x47bde0 in pkl_do_pass_1 /tmp/poke-2.0.92/libpoke/pkl-pass.c:603
    #4 0x47c20c in pkl_do_pass_1 /tmp/poke-2.0.92/libpoke/pkl-pass.c:364
    #5 0x47bf6c in pkl_do_pass_1 /tmp/poke-2.0.92/libpoke/pkl-pass.c:358
    #6 0x47e2a1 in pkl_do_pass_1 /tmp/poke-2.0.92/libpoke/pkl-pass.c:478
    #7 0x47bbbb in pkl_do_pass_1 /tmp/poke-2.0.92/libpoke/pkl-pass.c:344
    #8 0x4811ce in pkl_do_subpass /tmp/poke-2.0.92/libpoke/pkl-pass.c:639
    #9 0x481280 in pkl_do_pass /tmp/poke-2.0.92/libpoke/pkl-pass.c:661
    #10 0x4324ee in rest_of_compilation /tmp/poke-2.0.92/libpoke/pkl.c:290
    #11 0x43337b in pkl_execute_file /tmp/poke-2.0.92/libpoke/pkl.c:513
    #12 0x433777 in pkl_new /tmp/poke-2.0.92/libpoke/pkl.c:157
    #13 0x42b6e6 in pk_compiler_new_with_flags 
/tmp/poke-2.0.92/libpoke/libpoke.c:78
    #14 0x42b9e3 in pk_compiler_new /tmp/poke-2.0.92/libpoke/libpoke.c:99
    #15 0x405412 in initialize /tmp/poke-2.0.92/poke/poke.c:587
    #16 0x405412 in main /tmp/poke-2.0.92/poke/poke.c:784
    #17 0x7fc26e3f70b2 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #18 0x404bad in _start (/tmp/poke-2.0.92/poke/poke+0x404bad)

Seen with GCC 11.2 and also with clang 13.0.0.

pvm_val
pvm_make_int (int32_t value, int size)
{
  assert (0 < size && size <= 32);
  return PVM_MAKE_INT (value, size);
}

#define PVM_MAKE_INT(V,S)                       \
  (((((int64_t) (V)) & 0xffffffff) << 32)       \
   | ((((S) - 1) & 0x1f) << 3)                  \
   | PVM_VAL_TAG_INT)

As far as I understand, the left-hand-side of the '<< 32' evaluates to
(int64_t) 0x00000000ffffffff. The infinite-precision result of the shift
is thus   0x00....00ffffffff00000000, and this value is not within the
range of 'int64_t' (namely -0x8000000000000000 ... 0x7fffffffffffffff).

Find attached a fix. With it, './run poke/poke' no longer prints a
stack trace, and the only remaining test failures are

FAIL: poke.pkl/cdiv-integers-overflow-diag-1.pk (test for excess errors)
FAIL: poke.pkl/cdiv-integers-overflow-diag-2.pk (test for excess errors)
FAIL: poke.pkl/div-integers-overflow-diag-1.pk (test for excess errors)
FAIL: poke.pkl/div-integers-overflow-diag-2.pk (test for excess errors)
FAIL: poke.pkl/mod-integers-overflow-diag-1.pk (test for excess errors)
FAIL: poke.pkl/mod-integers-overflow-diag-2.pk (test for excess errors)
FAIL: poke.pkl/mul-integers-overflow-diag-3.pk (test for excess errors)
FAIL: poke.pkl/neg-int-overflow-diag-1.pk (test for excess errors)
FAIL: poke.pkl/neg-int-overflow-diag-2.pk (test for excess errors)
FAIL: poke.pkl/sub-integers-overflow-diag-1.pk (test for excess errors)
FAIL: poke.pkl/sub-integers-overflow-diag-2.pk (test for excess errors)
FAIL: poke.pkl/sub-integers-overflow-diag-3.pk (test for excess errors)

Attachment: 0001-Avoid-undefined-behaviour-on-signed-integer.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]