@@ -380,6 +380,31 @@ void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) {
unwrap(context_ref)->setOptPassGate(opt_bisect);
}
struct ZigDiagnosticHandler : public DiagnosticHandler {
bool BrokenDebugInfo;
ZigDiagnosticHandler() : BrokenDebugInfo(false) {}
bool handleDiagnostics(const DiagnosticInfo &DI) override {
// This dyn_cast should be casting to DiagnosticInfoIgnoringInvalidDebugMetadata
// but DiagnosticInfoIgnoringInvalidDebugMetadata is treated as DiagnosticInfoDebugMetadataVersion
// because of a bug in LLVM (see https://github.com/ziglang/zig/issues/19161).
// After this is fixed add an additional check for DiagnosticInfoIgnoringInvalidDebugMetadata
// but don't remove the current one as both indicate that debug info is broken.
if (auto *Remark = dyn_cast<DiagnosticInfoDebugMetadataVersion>(&DI)) {
BrokenDebugInfo = true;
}
return false;
}
};
void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref) {
unwrap(context_ref)->setDiagnosticHandler(std::make_unique<ZigDiagnosticHandler>());
}
bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref) {
return ((const ZigDiagnosticHandler*)
unwrap(context_ref)->getDiagHandlerPtr())->BrokenDebugInfo;
}
void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) {
cl::ParseCommandLineOptions(argc, argv);
}