Commit a558885321

Andrew Kelley <andrew@ziglang.org>
2025-07-13 21:15:19
LLVM backend: fixes
* delete dead code * don't access stack trace too early * revert unintended edit
1 parent 041bcbd
Changed files (3)
src
src/codegen/llvm.zig
@@ -1754,11 +1754,6 @@ pub const Object = struct {
         }
     }
 
-    pub fn freeDecl(self: *Object, decl_index: InternPool.DeclIndex) void {
-        const global = self.decl_map.get(decl_index) orelse return;
-        global.delete(&self.builder);
-    }
-
     fn getDebugFile(o: *Object, pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata {
         const gpa = o.gpa;
         const gop = try o.debug_file_map.getOrPut(gpa, file_index);
@@ -2596,9 +2591,8 @@ pub const Object = struct {
                 }
 
                 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {
-                    const stack_trace_ty = zcu.builtin_decl_values.get(.StackTrace);
-                    const ptr_ty = try pt.ptrType(.{ .child = stack_trace_ty });
-                    debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
+                    // Stack trace pointer.
+                    debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, .fromInterned(.ptr_usize_type)));
                 }
 
                 for (0..fn_info.param_types.len) |i| {
@@ -12901,26 +12895,6 @@ fn compilerRtIntBits(bits: u16) u16 {
     return bits;
 }
 
-fn getStackTraceType(pt: Zcu.PerThread) Allocator.Error!Type {
-    const zcu = pt.zcu;
-    const ip = &zcu.intern_pool;
-
-    const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
-    const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
-    const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index));
-    const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
-    const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
-
-    const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls);
-    // buffer is only used for int_type, `builtin` is a struct.
-    const builtin_ty = zcu.navValue(builtin_nav).toType();
-    const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu));
-    const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
-
-    // Sema should have ensured that StackTrace was analyzed.
-    return zcu.navValue(stack_trace_nav).toType();
-}
-
 fn buildAllocaInner(
     wip: *Builder.WipFunction,
     llvm_ty: Builder.Type,
src/link/Wasm.zig
@@ -3807,11 +3807,10 @@ pub fn flush(
     tid: Zcu.PerThread.Id,
     prog_node: std.Progress.Node,
 ) link.File.FlushError!void {
-    _ = tid;
-
     // The goal is to never use this because it's only needed if we need to
     // write to InternPool, but flush is too late to be writing to the
     // InternPool.
+    _ = tid;
     const comp = wasm.base.comp;
     const diags = &comp.link_diags;
     const gpa = comp.gpa;
src/Sema.zig
@@ -9705,7 +9705,6 @@ fn funcCommon(
             func_inst,
             cc_src,
             is_noinline,
-            is_generic,
         );
     }
 
@@ -9745,7 +9744,6 @@ fn funcCommon(
             func_inst,
             cc_src,
             is_noinline,
-            is_generic,
         );
     }
 
@@ -9762,7 +9760,6 @@ fn funcCommon(
         func_inst,
         cc_src,
         is_noinline,
-        is_generic,
     );
 }
 
@@ -9779,14 +9776,11 @@ fn finishFunc(
     func_inst: Zir.Inst.Index,
     cc_src: LazySrcLoc,
     is_noinline: bool,
-    is_generic: bool,
 ) CompileError!Air.Inst.Ref {
     const pt = sema.pt;
     const zcu = pt.zcu;
     const ip = &zcu.intern_pool;
     const gpa = sema.gpa;
-    const target = zcu.getTarget();
-    const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm);
 
     const return_type: Type = if (opt_func_index == .none or ret_poison)
         bare_return_type
@@ -9913,13 +9907,6 @@ fn finishFunc(
         }),
     }
 
-    if (backend == .stage2_llvm and !is_generic and sema.wantErrorReturnTracing(return_type)) {
-        // Make sure that StackTrace's fields are resolved so that the backend can
-        // lower this fn type.
-        const unresolved_stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(.zero), .StackTrace);
-        try unresolved_stack_trace_ty.resolveFields(pt);
-    }
-
     return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
 }