File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
src/compiler/crystal/codegen Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -2462,7 +2462,7 @@ module Crystal
2462
2462
global.linkage = LLVM ::Linkage ::Private
2463
2463
global.global_constant = true
2464
2464
global.initializer = llvm_context.const_struct [
2465
- type_id(@program .string),
2465
+ int32( @program .llvm_id. type_id(@program .string)), # in practice, should always be 1
2466
2466
int32(str.bytesize),
2467
2467
int32(str.size),
2468
2468
llvm_context.const_string(str),
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ class Crystal::CodeGenVisitor
65
65
end
66
66
67
67
private def type_id_impl (type )
68
- int(@program .llvm_id.type_id(type ))
68
+ type_id_name = " #{ type .llvm_name} :type_id"
69
+
70
+ global = @main_mod .globals[type_id_name]?
71
+ unless global
72
+ global = @main_mod .globals.add(@main_llvm_context .int32, type_id_name)
73
+ global.linkage = LLVM ::Linkage ::Internal if @single_module
74
+ global.initializer = @main_llvm_context .int32.const_int(@program .llvm_id.type_id(type ))
75
+ global.global_constant = true
76
+ end
77
+
78
+ if @llvm_mod != @main_mod
79
+ global = @llvm_mod .globals[type_id_name]?
80
+ unless global
81
+ global = @llvm_mod .globals.add(@llvm_context .int32, type_id_name)
82
+ global.linkage = LLVM ::Linkage ::External
83
+ global.global_constant = true
84
+ end
85
+ end
86
+
87
+ load(@llvm_context .int32, global)
69
88
end
70
89
end
You can’t perform that action at this time.
0 commit comments