Crystal: Attempt to bind a C library resulted in a compiler error

Created on 23 Apr 2018  路  4Comments  路  Source: crystal-lang/crystal

This is the line which caused the error: https://github.com/sherjilozair/cudnn.cr/blob/master/spec/cudnn_spec.cr#L18

The relevant pieces of code are:

describe CuDNN do
 it "allocates memory" do
   p = ::CuDNN.malloc(100)
   p.should be_a(Pointer(Void))
 end
end

which calls

module CuDNN
 extend self
 def malloc(size)
   check_success(LibCUDA.malloc(out ptr, size))
   return ptr
 end
end

which calls

@[Link("cudart")]
lib LibCUDA
 enum ErrorT
   Success
 end
 fun malloc = cudaMalloc(ptr : Void**, size : LibC::Int) : ErrorT
end

The error is:

Module validation failed: Incorrect number of arguments passed to called function!
  %0 = call %"String::Builder"* @"*Pointer(Void)@Object::to_s<String::Builder>:String::Builder"(i32 %obj, %"String::Builder"* %self), !dbg !148

???
???
???
???
???
???
???
???

Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

bug compiler

Most helpful comment

If module validation fails, it's a compiler bug, regardless of whether the input is valid or not.

p is not a keyword but a global method. It shouldn't be an issue if you name a local variable p.

All 4 comments

This was caused due to using p as a variable name. Apparently, p is a keyword in Crystal. Closing, since it's not a bug.

If module validation fails, it's a compiler bug, regardless of whether the input is valid or not.

p is not a keyword but a global method. It shouldn't be an issue if you name a local variable p.

Note that the reduced code doesn't reproduce the bug. Someone will have to remove the real bug from the git repo.

@bararchy fixed this on the repository, so he might have more information on how to extract the bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

straight-shoota picture straight-shoota  路  91Comments

fridgerator picture fridgerator  路  79Comments

benoist picture benoist  路  59Comments

rdp picture rdp  路  112Comments

stugol picture stugol  路  70Comments