This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Description
When we add hardware tracing some programs using specific libraries currently make the compiler segfault. The segfault happens in LLVM in a method called getInstructionIndex. This function essentially walks through a Bundle and skips all debug instructions until it finds a "real" instruction. LLVM expects to find at least 1 "real" instruction. The segfault happens, when the only instruction within the Bundle is a debug instruction. The segfault only happens when we enabled optimisations with -O.
What I think happens (though I'm not entirely sure), is that when enabling optimisations, LLVM optimises away some stuff, leaving an empty Bundle. Typically this Bundle would also be optimised away, however, since we inserted YK debug labels, the Bundle isn't actually empty and thus LLVM can't/doesn't remove it. Then LLVM tries to codegen the empty Bundle, but expects there to be at least one "real" instruction, which it cannot find and segfaults.
A possible solution to this problem is to disable hardware tracing when optimisations are enabled. I believe currently the debug labels are inaccurate anyways with optimisations on, since LLVM moves things around after they were inserted. So we may not be able to use optimisations anyways for the time being.