Skip to content

Integer sign-extension miscompile #423

@asumagic

Description

@asumagic

While writing a script bytecode->C->MIR compiler I hit what seems to be miscompilation of code that juggles with integer sizes.

I minified the repro as small as I could:

#include <stdio.h>
#include <stdint.h>

int64_t foo(int32_t* target, int32_t* b) {
        *target = 0xAAA + *b;
        return (int64_t)*target;
}

int main()
{
        /* prevents inline somehow */
        int64_t (*alias)(int32_t* target32, int32_t* b) = foo;
        int32_t target32;
        int b = -0xBBB;
        printf("%ld\n", alias(&target32, &b)); 
}

$ c2m repro.c -O3 -el
4294967023
$ c2m repro.c -O0 -el
-273

Tested on both master and v1.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions