aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-10-30 10:54:26 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-10-30 10:54:26 +0000
commit35a28053b8779ea7ab9845c31ad52fd55888667a (patch)
tree0808c843adc86b33da72bfa2739ca0f5597a6532 /src/llvm_backend_expr.cpp
parentbb44b02b3e220d7019aba8b547a6d3e6fbd49dba (diff)
parent074a8d7df5e024117d7f91944ccf053cad27ca0e (diff)
Merge branch 'master' into vendor/curl
Diffstat (limited to 'src/llvm_backend_expr.cpp')
-rw-r--r--src/llvm_backend_expr.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index ebc3ec158..187c34595 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -2502,7 +2502,6 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
}
for (Type *vt : dst->Union.variants) {
if (src_type == t_llvm_bool && is_type_boolean(vt)) {
- value = lb_emit_conv(p, value, vt);
lbAddr parent = lb_add_local_generated(p, t, true);
lb_emit_store_union_variant(p, parent.addr, value, vt);
return lb_addr_load(p, parent);
@@ -2563,10 +2562,11 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
Type *dt = t;
+ TEMPORARY_ALLOCATOR_GUARD();
+
GB_ASSERT(is_type_struct(st) || is_type_raw_union(st));
Selection sel = {};
- sel.index.allocator = heap_allocator();
- defer (array_free(&sel.index));
+ sel.index.allocator = temporary_allocator();
if (lookup_subtype_polymorphic_selection(t, src_type, &sel)) {
if (sel.entity == nullptr) {
GB_PANIC("invalid subtype cast %s -> ", type_to_string(src_type), type_to_string(t));
@@ -3929,6 +3929,20 @@ gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
return res;
}
+gb_internal Type *lb_build_expr_original_const_type(Ast *expr) {
+ expr = unparen_expr(expr);
+ Type *type = type_of_expr(expr);
+ if (is_type_union(type)) {
+ if (expr->kind == Ast_CallExpr) {
+ if (expr->CallExpr.proc->tav.mode == Addressing_Type) {
+ Type *res = lb_build_expr_original_const_type(expr->CallExpr.args[0]);
+ return res;
+ }
+ }
+ }
+ return type_of_expr(expr);
+}
+
gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
lbModule *m = p->module;
@@ -3940,9 +3954,11 @@ gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
GB_ASSERT_MSG(tv.mode != Addressing_Invalid, "invalid expression '%s' (tv.mode = %d, tv.type = %s) @ %s\n Current Proc: %.*s : %s", expr_to_string(expr), tv.mode, type_to_string(tv.type), token_pos_to_string(expr_pos), LIT(p->name), type_to_string(p->type));
+
if (tv.value.kind != ExactValue_Invalid) {
+ Type *original_type = lb_build_expr_original_const_type(expr);
// NOTE(bill): Short on constant values
- return lb_const_value(p->module, type, tv.value, LB_CONST_CONTEXT_DEFAULT_ALLOW_LOCAL);
+ return lb_const_value(p->module, type, tv.value, LB_CONST_CONTEXT_DEFAULT_ALLOW_LOCAL, original_type);
} else if (tv.mode == Addressing_Type) {
// NOTE(bill, 2023-01-16): is this correct? I hope so at least
return lb_typeid(m, tv.type);
@@ -4023,7 +4039,7 @@ gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
TypeAndValue tav = type_and_value_of_expr(expr);
GB_ASSERT(tav.mode == Addressing_Constant);
- return lb_const_value(p->module, type, tv.value);
+ return lb_const_value(p->module, type, tv.value, LB_CONST_CONTEXT_DEFAULT_ALLOW_LOCAL, tv.type);
case_end;
case_ast_node(se, SelectorCallExpr, expr);
@@ -4304,7 +4320,7 @@ gb_internal lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *exp
GB_ASSERT(e != nullptr);
if (e->kind == Entity_Constant) {
Type *t = default_type(type_of_expr(expr));
- lbValue v = lb_const_value(p->module, t, e->Constant.value);
+ lbValue v = lb_const_value(p->module, t, e->Constant.value, LB_CONST_CONTEXT_DEFAULT_NO_LOCAL, e->type);
if (LLVMIsConstant(v.value)) {
lbAddr g = lb_add_global_generated_from_procedure(p, t, v);
return g;