mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Fix #3964
This commit is contained in:
@@ -3288,11 +3288,12 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
if (!is_type_any(e->type) && !is_type_union(e->type)) {
|
if (!is_type_any(e->type) && !is_type_union(e->type)) {
|
||||||
if (tav.mode != Addressing_Invalid) {
|
if (tav.mode != Addressing_Invalid) {
|
||||||
if (tav.value.kind != ExactValue_Invalid) {
|
if (tav.value.kind != ExactValue_Invalid) {
|
||||||
|
bool is_rodata = e->kind == Entity_Variable && e->Variable.is_rodata;
|
||||||
ExactValue v = tav.value;
|
ExactValue v = tav.value;
|
||||||
lbValue init = lb_const_value(m, tav.type, v);
|
lbValue init = lb_const_value(m, tav.type, v, false, is_rodata);
|
||||||
LLVMSetInitializer(g.value, init.value);
|
LLVMSetInitializer(g.value, init.value);
|
||||||
var.is_initialized = true;
|
var.is_initialized = true;
|
||||||
if (e->kind == Entity_Variable && e->Variable.is_rodata) {
|
if (is_rodata) {
|
||||||
LLVMSetGlobalConstant(g.value, true);
|
LLVMSetGlobalConstant(g.value, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ gb_internal lbBlock *lb_create_block(lbProcedure *p, char const *name, bool appe
|
|||||||
|
|
||||||
gb_internal lbValue lb_const_nil(lbModule *m, Type *type);
|
gb_internal lbValue lb_const_nil(lbModule *m, Type *type);
|
||||||
gb_internal lbValue lb_const_undef(lbModule *m, Type *type);
|
gb_internal lbValue lb_const_undef(lbModule *m, Type *type);
|
||||||
gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true);
|
gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true, bool is_rodata=false);
|
||||||
gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value);
|
gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value);
|
||||||
gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value);
|
gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value);
|
||||||
|
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ gb_internal bool lb_is_nested_possibly_constant(Type *ft, Selection const &sel,
|
|||||||
return lb_is_elem_const(elem, ft);
|
return lb_is_elem_const(elem, ft);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local) {
|
gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local, bool is_rodata) {
|
||||||
LLVMContextRef ctx = m->ctx;
|
LLVMContextRef ctx = m->ctx;
|
||||||
|
|
||||||
type = default_type(type);
|
type = default_type(type);
|
||||||
@@ -565,6 +565,10 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo
|
|||||||
array_data = LLVMAddGlobal(m->mod, lb_type(m, t), str);
|
array_data = LLVMAddGlobal(m->mod, lb_type(m, t), str);
|
||||||
LLVMSetInitializer(array_data, backing_array.value);
|
LLVMSetInitializer(array_data, backing_array.value);
|
||||||
|
|
||||||
|
if (is_rodata) {
|
||||||
|
LLVMSetGlobalConstant(array_data, true);
|
||||||
|
}
|
||||||
|
|
||||||
lbValue g = {};
|
lbValue g = {};
|
||||||
g.value = array_data;
|
g.value = array_data;
|
||||||
g.type = t;
|
g.type = t;
|
||||||
|
|||||||
Reference in New Issue
Block a user