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

zig cc: illegal instruction generated for trivial pointer arithmetic #11324

Closed
qroq opened this issue Mar 27, 2022 · 2 comments
Closed

zig cc: illegal instruction generated for trivial pointer arithmetic #11324

qroq opened this issue Mar 27, 2022 · 2 comments

Comments

@qroq
Copy link

qroq commented Mar 27, 2022

Zig Version

0.10.0-dev.1617+dbbda0f41

Steps to Reproduce

Linux penguin 5.10.92-14540-g0aec27ec0722 #1 SMP PREEMPT Thu Mar 17 19:07:50 PDT 2022 x86_64 GNU/Linux
(this is linux running in chromeOS)

zig cc of the following:

int main()
{
int *should_be_0 = (int *)0 + 0;
return should_be_0 != 0;
}

give an illegal instruction:

(gdb) r
Starting program: /home/raible/interpreters/zig-linux-x86_64-0.10.0-dev.1617+dbbda0f41/a.out

Program received signal SIGILL, Illegal instruction.
main () at simple.c:3
3 int *should_be_0 = (int *)0 + 0;
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000201450 <+0>: push %rbp
0x0000000000201451 <+1>: mov %rsp,%rbp
=> 0x0000000000201454 <+4>: ud1 0x13(%eax),%eax
End of assembler dump.
(gdb)

Expected Behavior

No illegal instruction

Actual Behavior

Program crashes with an illegal instruction.

@qroq qroq added the bug Observed behavior contradicts documented or intended behavior label Mar 27, 2022
@Vexu
Copy link
Member

Vexu commented Mar 27, 2022

That is undefined behavior, compiling with clang gives:

a.c:3:29: runtime error: applying zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior a.c:3:29 in 

See https://github.com/ziglang/zig/wiki/FAQ#why-do-i-get-illegal-instruction-when-using-with-zig-cc-to-build-c-code

@Vexu Vexu closed this as completed Mar 27, 2022
@andrewrk
Copy link
Member

Related: #5163

@andrewrk andrewrk removed the bug Observed behavior contradicts documented or intended behavior label Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants