This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Crash treating array as pointer #123
Comments
Thanks to @xTachyon for the bug report! |
Note that this works fine without the offset: int puts(char*);
int f(int*);
int a[] = {1, 2, 3};
int main() {
f(a);
puts("works in f");
}
int f(int *a) {
a[0];
return *(a + 0);
}
$ ./a.out
works in f |
jyn514
added
bug
Something isn't working
codegen
Involves generating Cranelift IR
labels
Nov 28, 2019
|
Another little test program: int a[] = {1,2,3};
int printf(char*, ...);
int f(int*);
int main() {
printf("a: %p\n", a);
printf("a+1: %p\n", a+1);
printf("*a: %d\n", *a);
printf("a[1]: %d\n", a[1]);
printf("*(a+1): %d\n", *(a+1));
f(a);
}
int f(int *p) {
printf("p: %p\n", p);
printf("p+1: %p\n", p+1);
printf("*p: %d\n", *p);
printf("p[1]: %d\n", p[1]);
printf("*(p+1): %d\n", *(p+1));
return 0;
} Current output:
Output calling
|
Writing down what I'm doing because I keep going in circles:
This is missing the final deref of |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Segfault
Expected behavior
The array element is dereferenced and returned.
Actual Behavior
The program segfaults at runtime.
Code
AST
Please paste the output of
cargo run -- --debug-ast
here.ASM
Please paste the output of
cargo run -- --debug-asm
here.The text was updated successfully, but these errors were encountered: