authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-03-02 15:19:09+01:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-03-02 20:53:06+01:00
loge2345f006ffcd17e41aa73b27890044a0e1f2218
tree7f220ca6cdd8bb06668d6d3196583e2eb915b347
parent9d500bda2d09fe67c39ee98067c1e53c58adbd5e

LLVM: Add enableBrokenDebugInfoCheck and getBrokenDebugInfo

These functions allows the caller to find out wether the context encounters broken debug info or not.

3 files changed, 29 insertions(+), 0 deletions(-)

src/codegen/llvm/bindings.zig+6
......@@ -37,6 +37,12 @@ pub const Context = opaque {
3737
3838 pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit;
3939 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;
4046};
4147
4248pub const Module = opaque {
src/zig_llvm.cpp+20
......@@ -380,6 +380,26 @@ void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) {
380380 unwrap(context_ref)->setOptPassGate(opt_bisect);
381381}
382382
383struct ZigDiagnosticHandler : public DiagnosticHandler {
384 bool BrokenDebugInfo;
385 ZigDiagnosticHandler() : BrokenDebugInfo(false) {}
386 bool handleDiagnostics(const DiagnosticInfo &DI) override {
387 if (auto *Remark = dyn_cast<DiagnosticInfoDebugMetadataVersion>(&DI)) {
388 BrokenDebugInfo = true;
389 }
390 return false;
391 }
392};
393
394void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref) {
395 unwrap(context_ref)->setDiagnosticHandler(std::make_unique<ZigDiagnosticHandler>());
396}
397
398bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref) {
399 return ((const ZigDiagnosticHandler*)
400 unwrap(context_ref)->getDiagHandlerPtr())->BrokenDebugInfo;
401}
402
383403void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) {
384404 cl::ParseCommandLineOptions(argc, argv);
385405}
src/zig_llvm.h+3
......@@ -44,6 +44,9 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co
4444
4545ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit);
4646
47ZIG_EXTERN_C void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref);
48ZIG_EXTERN_C bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref);
49
4750enum ZigLLVMTailCallKind {
4851 ZigLLVMTailCallKindNone,
4952 ZigLLVMTailCallKindTail,