Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various: Fix gcc -fsanitize=undefined errors #7237

Closed
wants to merge 1 commit into from

Commits on May 10, 2021

  1. various: Fix gcc -fsanitize=undefined errors.

    [messages truncated to pass ci_commit_formatting_run]
    [the line numbers match 0e87459]
    ```
    binary.c:210:13: runtime error: left shift of negative val...
    crypto-algorithms/sha256.c:49:19: runtime error: left shif...
    moduasyncio.c:106:35: runtime error: member access within ...
    mpz.c:711:5: runtime error: null pointer passed as argumen...
    mpz.c:744:16: runtime error: negation of -9223372036854775...
    objarray.c:130:9: runtime error: null pointer passed as ar...
    objarray.c:377:5: runtime error: null pointer passed as ar...
    objarray.c:457:21: runtime error: null pointer passed as a...
    objarray.c:457:21: runtime error: null pointer passed as a...
    objarray.c:461:21: runtime error: null pointer passed as a...
    objdict.c:250:5: runtime error: null pointer passed as arg...
    objdict.c:250:5: runtime error: null pointer passed as arg...
    objint.c:109:22: runtime error: left shift of # by 31 plac...
    objint_mpz.c:374:9: runtime error: left shift of # by 1 pl...
    objint_mpz.c:374:9: runtime error: left shift of negative ...
    objset.c:181:5: runtime error: null pointer passed as argu...
    objset.c:181:5: runtime error: null pointer passed as argu...
    parsenum.c:106:14: runtime error: left shift of # by 1 pla...
    qstr.c:181:78: runtime error: null pointer passed as argum...
    runtime.c:395:33: runtime error: left shift of negative va...
    runtime.c:534:17: runtime error: left shift of negative va...
    sequence.c:108:15: runtime error: null pointer passed as a...
    sequence.c:108:15: runtime error: null pointer passed as a...
    showbc.c:177:28: runtime error: left shift of negative val...
    vm.c:321:36: runtime error: left shift of negative value -...
    ```
    
    With these cumulative changes, `make VARIANT=coverage test_full`
    with -fsanitize=undefined passes, except for some problems in axtls.
    
    My testing was done on an amd64 debian buster system using gcc-8.3 and
    these settings:
    ```
    CFLAGS += -g3 -Og -fsanitize=undefined
    LDFLAGS += -fsanitize=undefined
    ```
    
    The changes are intended/expected to produce no runtime overhead, as the
    behavior of the mem* functions is only actually modified for the unix
    coverage run (MICROPY_NONNULL_COMPLIANT).
    
    The introduced PAIRHEAP macro's conditional (x ? &x->i : NULL) assembles
    (under amd64 gcc 8.3 -Os) to the same as &x->i, since i is the initial
    field of the struct.  However, for the purposes of undefined behavior
    analysis the conditional is needed.
    
    Signed-off-by: Jeff Epler <jepler@gmail.com>
    jepler committed May 10, 2021
    Configuration menu
    Copy the full SHA
    cc74f22 View commit details
    Browse the repository at this point in the history