authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-12 17:41:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-13 03:07:50-07:00
log69dc1a6bb28dc47a57902d421c538f2f82edea8a
treef135f58d394e18deeb0ec8ecd70ac0534e0ac58c
parent2769215b9037bb1f407e07887d4d21957ce1a9e0

llvm: fix incorrect file paths in debug info

The previous code incorrectly added `sub_path` twice. Also for the compilation unit, it was passing empty string to realpath, resulting in the error handling codepath being used. closes #17482

1 files changed, 5 insertions(+), 3 deletions(-)

src/codegen/llvm.zig+5-3
......@@ -898,10 +898,11 @@ pub const Object = struct {
898898 // very location dependent.
899899 // TODO: the only concern I have with this is WASI as either host or target, should
900900 // we leave the paths as relative then?
901 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
902901 const compile_unit_dir_z = blk: {
903 if (options.module) |mod| {
902 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
903 if (options.module) |mod| m: {
904904 const d = try mod.root_mod.root.joinStringZ(builder.gpa, "");
905 if (d.len == 0) break :m;
905906 if (std.fs.path.isAbsolute(d)) break :blk d;
906907 const abs = std.fs.realpath(d, &buf) catch break :blk d;
907908 builder.gpa.free(d);
......@@ -1840,7 +1841,8 @@ pub const Object = struct {
18401841 const dir_path = try file.mod.root.joinStringZ(gpa, sub_path);
18411842 if (std.fs.path.isAbsolute(dir_path)) break :d dir_path;
18421843 const abs = std.fs.realpath(dir_path, &buffer) catch break :d dir_path;
1843 break :d try std.fs.path.joinZ(gpa, &.{ abs, sub_path });
1844 gpa.free(dir_path);
1845 break :d try gpa.dupeZ(u8, abs);
18441846 };
18451847 defer gpa.free(dir_path_z);
18461848 const sub_file_path_z = try gpa.dupeZ(u8, std.fs.path.basename(file.sub_file_path));