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

Incorrect IR codegen for overflowing integer constants #1

Open
DontBelieveMe opened this issue Nov 30, 2021 · 0 comments
Open

Incorrect IR codegen for overflowing integer constants #1

DontBelieveMe opened this issue Nov 30, 2021 · 0 comments
Assignees
Labels
bug Something isn't working frontend Relating to the C language frontend ir Relating to the IR

Comments

@DontBelieveMe
Copy link
Owner

Given this C code

int main() {
	unsigned char my_byte = 1000;
	return 0;
}

the following IR is generated

function main(): i32 {
.0:
        stack_alloc [i8 x 1], %0:ptr
        store 1000:i8, %0:ptr
        ret 0:i32
}

Of course you can't store 1000 in an i8, so this should wrap the integer around correctly 232.

(In fact clang actually warns about this, and gives this

C:\helix\.\testsuite\f.c:4:15: warning: implicit conversion from 'int' to 'u8' (aka 'unsigned char') changes value from
      1000 to 232 [-Wconstant-conversion]
        u8 my_byte = 1000;
           ~~~~~~~   ^~~~
@DontBelieveMe DontBelieveMe added bug Something isn't working frontend Relating to the C language frontend ir Relating to the IR labels Nov 30, 2021
@DontBelieveMe DontBelieveMe self-assigned this Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend Relating to the C language frontend ir Relating to the IR
Projects
None yet
Development

No branches or pull requests

1 participant