Commit 8b66443d50

Jacob Young <jacobly0@users.noreply.github.com>
2022-10-01 10:01:35
llvm: avoid undefined values by ensuring the StackTrace decl is analyzed
The test builds an object file to prevent StackTrace from already having been analyzed by other code. Fixes #13030
1 parent d9490a4
Changed files (4)
src
codegen
test
standalone
issue_13030
src/codegen/llvm.zig
@@ -2335,6 +2335,7 @@ pub const Object = struct {
         const stack_trace_decl = builtin_namespace.decls
             .getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .mod = mod }).?;
 
+        mod.ensureDeclAnalyzed(stack_trace_decl) catch unreachable;
         return mod.declPtr(stack_trace_decl).val.toType(undefined);
     }
 };
test/standalone/issue_13030/build.zig
@@ -0,0 +1,18 @@
+const std = @import("std");
+const builtin = @import("builtin");
+const Builder = std.build.Builder;
+const CrossTarget = std.zig.CrossTarget;
+
+pub fn build(b: *Builder) void {
+    const mode = b.standardReleaseOptions();
+    const target = b.standardTargetOptions(.{});
+
+    const obj = b.addObject("main", "main.zig");
+    obj.setBuildMode(mode);
+
+    obj.setTarget(target);
+    b.default_step.dependOn(&obj.step);
+
+    const test_step = b.step("test", "Test the program");
+    test_step.dependOn(&obj.step);
+}
test/standalone/issue_13030/main.zig
@@ -0,0 +1,8 @@
+const std = @import("std");
+fn a() error{}!void {}
+fn b() std.meta.FnPtr(fn () error{}!void) {
+    return &a;
+}
+export fn c() void {
+    _ = b();
+}
test/standalone.zig
@@ -97,4 +97,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
     // Disabled due to tripping LLVM 13 assertion:
     // https://github.com/ziglang/zig/issues/12015
     //cases.add("tools/update_spirv_features.zig");
+
+    cases.addBuildFile("test/standalone/issue_13030/build.zig", .{ .build_modes = true });
 }