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

Refactor some target flag uses #11466

Merged
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
253 changes: 126 additions & 127 deletions spec/compiler/codegen/c_abi/c_abi_x86_64_spec.cr
Original file line number Diff line number Diff line change
@@ -1,164 +1,163 @@
{% skip_file unless flag?(:x86_64) && !flag?(:win32) %}
require "../../../spec_helper"

{% if flag?(:x86_64) && !flag?(:win32) %}
describe "Code gen: C ABI x86_64" do
it "passes struct less than 64 bits as { i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end

fun foo(s : Struct)
describe "Code gen: C ABI x86_64" do
it "passes struct less than 64 bits as { i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end

s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void @foo({ i64 }")
str.should contain("declare void @foo({ i64 })")
end
fun foo(s : Struct)
end

it "passes struct less than 64 bits as { i64 } in varargs" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end
s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void @foo({ i64 }")
str.should contain("declare void @foo({ i64 })")
end

fun foo(...)
it "passes struct less than 64 bits as { i64 } in varargs" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end

s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void (...)")
end
fun foo(...)
end

it "passes struct between 64 and 128 bits as { i64, i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int16
end
s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void (...)")
end

fun foo(s : Struct)
it "passes struct between 64 and 128 bits as { i64, i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int16
end

s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void @foo({ i64, i64 }")
str.should contain("declare void @foo({ i64, i64 })")
end
fun foo(s : Struct)
end

it "passes struct between 64 and 128 bits as { i64, i64 } (with multiple modules/contexts)" do
codegen(%(
require "prelude"
s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.should contain("call void @foo({ i64, i64 }")
str.should contain("declare void @foo({ i64, i64 })")
end

lib LibFoo
struct Struct
x : Int64
y : Int16
end
it "passes struct between 64 and 128 bits as { i64, i64 } (with multiple modules/contexts)" do
codegen(%(
require "prelude"

fun foo(s : Struct)
lib LibFoo
struct Struct
x : Int64
y : Int16
end

module Moo
def self.moo
s = LibFoo::Struct.new
LibFoo.foo(s)
end
end
fun foo(s : Struct)
end

Moo.moo
))
end
module Moo
def self.moo
s = LibFoo::Struct.new
LibFoo.foo(s)
end
end

it "passes struct bigger than128 bits with byval" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int64
z : Int8
end
Moo.moo
))
end

fun foo(s : Struct)
it "passes struct bigger than128 bits with byval" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int64
z : Int8
end

s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.scan(/byval/).size.should eq(2)
end
fun foo(s : Struct)
end

it "returns struct less than 64 bits as { i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end
s = LibFoo::Struct.new
LibFoo.foo(s)
))
str = mod.to_s
str.scan(/byval/).size.should eq(2)
end

fun foo : Struct
it "returns struct less than 64 bits as { i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int8
y : Int16
end

str = LibFoo.foo
))
str = mod.to_s
str.should contain("call { i64 } @foo()")
str.should contain("declare { i64 } @foo()")
end
fun foo : Struct
end

it "returns struct between 64 and 128 bits as { i64, i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int16
end
str = LibFoo.foo
))
str = mod.to_s
str.should contain("call { i64 } @foo()")
str.should contain("declare { i64 } @foo()")
end

fun foo : Struct
it "returns struct between 64 and 128 bits as { i64, i64 }" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int16
end

str = LibFoo.foo
))
str = mod.to_s
str.should contain("call { i64, i64 } @foo()")
str.should contain("declare { i64, i64 } @foo()")
end
fun foo : Struct
end

it "returns struct bigger than 128 bits with sret" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int64
z : Int8
end
str = LibFoo.foo
))
str = mod.to_s
str.should contain("call { i64, i64 } @foo()")
str.should contain("declare { i64, i64 } @foo()")
end

fun foo(w : Int32) : Struct
it "returns struct bigger than 128 bits with sret" do
mod = codegen(%(
lib LibFoo
struct Struct
x : Int64
y : Int64
z : Int8
end

str = LibFoo.foo(1)
))
str = mod.to_s
str.scan(/sret/).size.should eq(2)

if LibLLVM::IS_LT_120
str.should contain("sret, i32") # sret goes as first argument
else
str.should contain("sret(%\"struct.LibFoo::Struct\") %0, i32") # sret goes as first argument
fun foo(w : Int32) : Struct
end

str = LibFoo.foo(1)
))
str = mod.to_s
str.scan(/sret/).size.should eq(2)

if LibLLVM::IS_LT_120
str.should contain("sret, i32") # sret goes as first argument
else
str.should contain("sret(%\"struct.LibFoo::Struct\") %0, i32") # sret goes as first argument
end
end
{% end %}
end
2 changes: 1 addition & 1 deletion spec/compiler/codegen/if_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe "Code gen: if" do
)).to_i.should eq(3)
end

{% if flag?(:x86_64) %}
{% if flag?(:bits64) %}
it "codegens if with pointer 0x100000000 pointer" do
run(%(
ptr = Pointer(Void).new(0x100000000_u64)
Expand Down
Loading