Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active June 22, 2020 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oprypin/2b55488a79d106b85729d610a790d8ff to your computer and use it in GitHub Desktop.
Save oprypin/2b55488a79d106b85729d610a790d8ff to your computer and use it in GitHub Desktop.
Bug in C ABI when using large function signature with a struct
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
cl /c test.c /Fotest.o && crystal test.cr
gcc -c test.c && crystal test.cr
#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
@[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