From 30864196acee0c474d224b641f289e2dfa418d5f Mon Sep 17 00:00:00 2001 From: asterite Date: Thu, 8 Feb 2018 09:00:42 -0300 Subject: [PATCH] Fix incorrect type for lib extern static array --- spec/compiler/codegen/lib_spec.cr | 10 ++++++++++ src/compiler/crystal/codegen/llvm_typer.cr | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/spec/compiler/codegen/lib_spec.cr b/spec/compiler/codegen/lib_spec.cr index 48762e4f9726..e899bcf6d2cf 100644 --- a/spec/compiler/codegen/lib_spec.cr +++ b/spec/compiler/codegen/lib_spec.cr @@ -227,4 +227,14 @@ describe "Code gen: lib" do LibFoo.foo(x) )) end + + it "uses static array in lib extern (#5688)" do + codegen(%( + lib LibFoo + $x : Int32[10] + end + + LibFoo.x + )) + end end diff --git a/src/compiler/crystal/codegen/llvm_typer.cr b/src/compiler/crystal/codegen/llvm_typer.cr index 8bcb4e3bad4d..7be68a3e5bf2 100644 --- a/src/compiler/crystal/codegen/llvm_typer.cr +++ b/src/compiler/crystal/codegen/llvm_typer.cr @@ -452,6 +452,12 @@ module Crystal end end + # StaticArray can only be "returned" in lib externs, + # not in C functions, and there it must not be a pointer. + def llvm_c_return_type(type : StaticArrayInstanceType) + llvm_struct_type(type) + end + def llvm_c_return_type(type : NilType) @llvm_context.void end