I’ve checked the target triple’s architecture and it says its x86_64 but when I pass it to createTargetMachine the switch case fails and errors saying “Invalid architecture value”
==17233== at 0x571018B: raise (raise.c:51)
==17233== by 0x56EF858: abort (abort.c:79)
==17233== by 0x7C7FC3: llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) (ErrorHandling.cpp:209)
==17233== by 0x80C9E0: getArchPointerBitWidth(llvm::Triple::ArchType) (Triple.cpp:1338)
==17233== by 0x80CA06: llvm::Triple::isArch64Bit() const (Triple.cpp:1342)
==17233== by 0xD62F4E: llvm::X86_MC::ParseX86Triple[abi:cxx11](llvm::Triple const&) (X86MCTargetDesc.cpp:49)
==17233== by 0xD631DE: llvm::X86_MC::createX86MCSubtargetInfo(llvm::Triple const&, llvm::StringRef, llvm::StringRef) (X86MCTargetDesc.cpp:290)
==17233== by 0x3EE6B9: llvm::Target::createTargetMachine(llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::TargetOptions const&, llvm::Optional<llvm::Reloc::Model>, llvm::Optional<llvm::CodeModel::Model>, llvm::CodeGenOpt::Level, bool) const (in /home/jack/Projects/blast/build/blast)
==17233== by 0x3ED346: CodegenContext::Codegen(void*) (in /home/jack/Projects/blast/build/blast)
==17233== by 0x3ED152: CodegenContext::Codegen(void*) (in /home/jack/Projects/blast/build/blast)
==17233== by 0x3F20B4: Editor::Update() (in /home/jack/Projects/blast/build/blast)
==17233== by 0x3F61D7: main (in /home/jack/Projects/blast/build/blast)
Something is really strange here, can you try to modify the code at Triple.cpp:1342 to print what kind of enum value you get here?
Also maybe try to build and test with ASAN.
Right now your error message changed though: the printing does not help when the error isn’t the same…
Also this isn’t a Valgrind failure but an assertion in the code. We’d need a reproducer to figure out what’s happening here, but it went beyond you createTargetMachine call.
ASAN standard for Address Sanitizer, if you know Valgrind then it does kind of the same thing. For LLVM the CMake option to enable it is -DLLVM_USE_SANITIZER=Address, the clang flag is -fsanitize=address. See also UBSAN: UndefinedBehaviorSanitizer — Clang 13 documentation
So I’ve done a bit more debugging and its now crashing on the actual codegen pass (specifically llvm::LegacyPassManager.run(llvm::Module* module)), it looks like its casting an instruction to llvm::UnreachableInst and crashing on that (I have literally no clue what that means)
It’s crashing on a nullptr instruction, this shouldn’t happen, at least assuming the verifier passes before you run the pass manager: double-checking is the IR you’re providing to the pass manager valid?
Can you dump it if it isn’t too large?