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

Fix bug with passing many args then a struct in Win64 C lib ABI #9520

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions spec/compiler/codegen/c_abi/c_abi_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ describe "Code gen: C ABI" do
), &.to_i.should eq(6))
end

{% if flag?(:x86_64) && !flag?(:win32) %}
pending "passes struct after many other args (for real) (#9519)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the spec does not apply on non-windows platform?

Copy link
Member

@jhass jhass Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's broken there too, but a bit harder to fix (and maybe arguably out of scope here, wanting to fix it for the windows ABI).

The actual spec is below and enabled for windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

{% else %}
it "passes struct after many other args (for real)" do
test_c(
%(
struct s {
long long x, y;
};

long long foo(long long a, long long b, long long c, long long d, long long e, struct s v) {
return a + b + c + d + e + v.x + v.y;
}
),
%(
lib LibFoo
struct S
x : Int64
y : Int64
end

fun foo(a : Int64, b : Int64, c : Int64, d : Int64, e : Int64, v : S) : Int64
end

v = LibFoo::S.new(x: 6, y: 7)
LibFoo.foo(1, 2, 3, 4, 5, v)
), &.to_string.should eq("28"))
end
{% end %}

it "returns struct less than 64 bits (for real)" do
test_c(
%(
Expand Down
2 changes: 1 addition & 1 deletion src/llvm/abi/x86_win64.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LLVM::ABI::X86_Win64 < LLVM::ABI::X86
when 2 then ArgType.direct(t, context.int16)
when 4 then ArgType.direct(t, context.int32)
when 8 then ArgType.direct(t, context.int64)
else ArgType.indirect(t, LLVM::Attribute::ByVal)
else ArgType.indirect(t, nil)
end
else
non_struct(t, context)
Expand Down