-
-
Save oprypin/2b55488a79d106b85729d610a790d8ff to your computer and use it in GitHub Desktop.
Bug in C ABI when using large function signature with a struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clang -DMain -S -emit-llvm test.c && mv test{,.c}.ll | |
crystal build --prelude=empty --no-debug --emit=llvm-ir test.cr && mv test{,.cr}.ll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cl /c test.c /Fotest.o && crystal test.cr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc -c test.c && crystal test.cr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef struct Vec { | |
long long x; | |
long long y; | |
} Vec; | |
void foo(long long a, long long b, long long c, long long d, long long e, Vec v) { | |
printf("%lld %lld %lld %lld %lld %lld %lld\n", a, b, c, d, e, v.x, v.y); | |
// 1 2 3 4 5 7 139713085455776 | |
} | |
#ifdef Main | |
int main() { | |
Vec v = {6, 7}; | |
foo(1, 2, 3, 4, 5, v); | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@[Link(ldflags: "#{__DIR__}/test.o")] | |
lib Lib | |
struct Vec | |
x : Int64 | |
y : Int64 | |
end | |
fun foo(Int64, Int64, Int64, Int64, Int64, Vec) | |
end | |
Lib.foo(1, 2, 3, 4, 5, Lib::Vec.new(x: 6, y: 7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment