| author | |
| committer | |
| log | 90c1a2c41aafb1e35e075fb7d0bdcf04c00db913 |
| tree | 1037ffb947dc331e68a1dba73e590771113dcec3 |
| parent | 33de937fd91c64cd65894369cf7d92665a8e582e |
| parent | 282b398f6da967f413e223b452457d37e93a70b3 |
| signature |
LLVM: Fail to emit if LLVM encounters broken debug info4 files changed, 38 insertions(+), 2 deletions(-)
src/codegen/llvm.zig+4-2| ... | @@ -1245,9 +1245,11 @@ pub const Object = struct { | ... | @@ -1245,9 +1245,11 @@ pub const Object = struct { |
| 1245 | ); | 1245 | ); |
| 1246 | defer bitcode_memory_buffer.dispose(); | 1246 | defer bitcode_memory_buffer.dispose(); |
| 1247 | 1247 | ||
| 1248 | context.enableBrokenDebugInfoCheck(); | ||
| 1249 | |||
| 1248 | var module: *llvm.Module = undefined; | 1250 | var module: *llvm.Module = undefined; |
| 1249 | if (context.parseBitcodeInContext2(bitcode_memory_buffer, &module).toBool()) { | 1251 | if (context.parseBitcodeInContext2(bitcode_memory_buffer, &module).toBool() or context.getBrokenDebugInfo()) { |
| 1250 | std.debug.print("Failed to parse bitcode\n", .{}); | 1252 | log.err("Failed to parse bitcode", .{}); |
| 1251 | return error.FailedToEmit; | 1253 | return error.FailedToEmit; |
| 1252 | } | 1254 | } |
| 1253 | break :emit .{ context, module }; | 1255 | break :emit .{ context, module }; |
src/codegen/llvm/bindings.zig+6| ... | @@ -37,6 +37,12 @@ pub const Context = opaque { | ... | @@ -37,6 +37,12 @@ pub const Context = opaque { |
| 37 | 37 | ||
| 38 | pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit; | 38 | pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit; |
| 39 | extern fn ZigLLVMSetOptBisectLimit(C: *Context, limit: c_int) void; | 39 | extern fn ZigLLVMSetOptBisectLimit(C: *Context, limit: c_int) void; |
| 40 | |||
| 41 | pub const enableBrokenDebugInfoCheck = ZigLLVMEnableBrokenDebugInfoCheck; | ||
| 42 | extern fn ZigLLVMEnableBrokenDebugInfoCheck(C: *Context) void; | ||
| 43 | |||
| 44 | pub const getBrokenDebugInfo = ZigLLVMGetBrokenDebugInfo; | ||
| 45 | extern fn ZigLLVMGetBrokenDebugInfo(C: *Context) bool; | ||
| 40 | }; | 46 | }; |
| 41 | 47 | ||
| 42 | pub const Module = opaque { | 48 | pub const Module = opaque { |
src/zig_llvm.cpp+25| ... | @@ -380,6 +380,31 @@ void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) { | ... | @@ -380,6 +380,31 @@ void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) { |
| 380 | unwrap(context_ref)->setOptPassGate(opt_bisect); | 380 | unwrap(context_ref)->setOptPassGate(opt_bisect); |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | struct ZigDiagnosticHandler : public DiagnosticHandler { | ||
| 384 | bool BrokenDebugInfo; | ||
| 385 | ZigDiagnosticHandler() : BrokenDebugInfo(false) {} | ||
| 386 | bool handleDiagnostics(const DiagnosticInfo &DI) override { | ||
| 387 | // This dyn_cast should be casting to DiagnosticInfoIgnoringInvalidDebugMetadata | ||
| 388 | // but DiagnosticInfoIgnoringInvalidDebugMetadata is treated as DiagnosticInfoDebugMetadataVersion | ||
| 389 | // because of a bug in LLVM (see https://github.com/ziglang/zig/issues/19161). | ||
| 390 | // After this is fixed add an additional check for DiagnosticInfoIgnoringInvalidDebugMetadata | ||
| 391 | // but don't remove the current one as both indicate that debug info is broken. | ||
| 392 | if (auto *Remark = dyn_cast<DiagnosticInfoDebugMetadataVersion>(&DI)) { | ||
| 393 | BrokenDebugInfo = true; | ||
| 394 | } | ||
| 395 | return false; | ||
| 396 | } | ||
| 397 | }; | ||
| 398 | |||
| 399 | void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref) { | ||
| 400 | unwrap(context_ref)->setDiagnosticHandler(std::make_unique<ZigDiagnosticHandler>()); | ||
| 401 | } | ||
| 402 | |||
| 403 | bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref) { | ||
| 404 | return ((const ZigDiagnosticHandler*) | ||
| 405 | unwrap(context_ref)->getDiagHandlerPtr())->BrokenDebugInfo; | ||
| 406 | } | ||
| 407 | |||
| 383 | void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { | 408 | void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { |
| 384 | cl::ParseCommandLineOptions(argc, argv); | 409 | cl::ParseCommandLineOptions(argc, argv); |
| 385 | } | 410 | } |
src/zig_llvm.h+3| ... | @@ -44,6 +44,9 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co | ... | @@ -44,6 +44,9 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co |
| 44 | 44 | ||
| 45 | ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit); | 45 | ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit); |
| 46 | 46 | ||
| 47 | ZIG_EXTERN_C void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref); | ||
| 48 | ZIG_EXTERN_C bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref); | ||
| 49 | |||
| 47 | enum ZigLLVMTailCallKind { | 50 | enum ZigLLVMTailCallKind { |
| 48 | ZigLLVMTailCallKindNone, | 51 | ZigLLVMTailCallKindNone, |
| 49 | ZigLLVMTailCallKindTail, | 52 | ZigLLVMTailCallKindTail, |