Closed
Description
Code:
(http://carc.in/#/r/1kr)
class My
def initialize(@name=self)
end
def display_self
string = " #{@name.class}"
puts string
end
end
my = My.new
my.display_self
Output:
; ModuleID = 'My'
%String = type { i32, i32, i32, i8 }
%My = type { i32, i32 }
%"String::Builder" = type { i32, i8*, i32, i32, i1 }
@symbol_table = external global [1 x %String*]
@str = private constant { i32, i32, i32, [2 x i8] } { i32 1, i32 1, i32 1, [2 x i8] c" \00" }
define %My* @"*My::new:My"() {
entry:
%0 = call %My* @"*My::new<My:Class>:My"(i32 330)
ret %My* %0
}
define %My* @"*My::new<My:Class>:My"(i32 %name) {
alloca:
%_ = alloca %My*
br label %entry
entry: ; preds = %alloca
%0 = call i8* @__crystal_malloc(i32 trunc (i64 mul nuw (i64 ptrtoint (i32* getelementptr (i32* null, i32 1) to i64), i64 2) to i32))
%1 = bitcast i8* %0 to %My*
%2 = bitcast %My* %1 to i8*
call void @llvm.memset.p0i8.i32(i8* %2, i8 0, i32 trunc (i64 mul nuw (i64 ptrtoint (i32* getelementptr (i32* null, i32 1) to i64), i64 2) to i32), i32 4, i1 false)
%3 = getelementptr inbounds %My* %1, i32 0, i32 0
store i32 72, i32* %3
store %My* %1, %My** %_
%4 = load %My** %_
%5 = call i32 @"*My#initialize<My, My:Class>:My:Class"(%My* %4, i32 %name)
%6 = load %My** %_
%7 = call i1 @"*GC::add_finalizer<My>:Nil"(%My* %6)
%8 = load %My** %_
ret %My* %8
}
declare i8* @__crystal_malloc(i32)
; Function Attrs: nounwind
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0
define i32 @"*My#initialize<My, My:Class>:My:Class"(%My* %self, i32 %name) {
entry:
%0 = getelementptr inbounds %My* %self, i32 0, i32 1
store i32 %name, i32* %0
ret i32 %name
}
declare i1 @"*GC::add_finalizer<My>:Nil"(%My*)
define i1 @"*My#display_self<My>:Nil"(%My* %self) {
alloca:
%string = alloca %String*
entry: ; No predecessors!
%0 = call %"String::Builder"* @"*String::Builder::new:String::Builder"()
%1 = call %"String::Builder"* @"*String::Builder@IO#<<<String::Builder, String>:String::Builder"(%"String::Builder"* %0, %String* bitcast ({ i32, i32, i32, [2 x i8] }* @str to %String*))
}
declare %"String::Builder"* @"*String::Builder::new:String::Builder"()
declare %"String::Builder"* @"*String::Builder@IO#<<<String::Builder, String>:String::Builder"(%"String::Builder"*, %String*)
attributes #0 = { nounwind }
Bug: trying to downcast Class <- My
_init +170751 [0]
_init +3262746 [0]
_init +3257455 [0]
_init +3389123 [0]
_init +3311148 [0]
_init +3284496 [0]
_init +3356460 [0]
_init +3310937 [0]
_init +3284496 [0]
_init +3355957 [0]
_init +3310937 [0]
_init +3284496 [0]
_init +3442057 [0]
_init +3287946 [0]
_init +3287030 [0]
_init +3364619 [0]
_init +3360521 [0]
_init +3313364 [0]
_init +3284496 [0]
_init +3159268 [0]
_init +3145978 [0]
_init +2421205 [0]
_init +215240 [0]
_init +194090 [0]
__libc_start_main +247 [0]
_init +167719 [0]
Error: you've found a bug in the Crystal compiler. Please open an issue: https://github.com/manastech/crystal/issues
Activity