I am currently trying to map all LLVM instructions of a program to their respective locations in the source code, wherever possible. However, I found that in many cases I have to deal with llvm.dbg.value instructions, which are quite a bit more complex when it comes to mapping them to their right source location. Judging from the LLVM wiki, I understood that these intrinsics are introduced by optimization passes, and replace llvm.dbg.declare instructions. There it says:
A frontend should generate exactly one call to
llvm.dbg.declareat the point of declaration of a source variable. Optimization passes that fully promote the variable from memory to SSA values will replace this call with possibly multiple calls to llvm.dbg.value.
So in theory I would have guessed that avoiding any optimizations, would also avoid any introduction of llvm.dbg.value instructions. And indeed, with smaller examples, this seems to be exactly the case. However, when I tried to compile larger software projects, such as bash or ngninx, I found that calls to llvm.dbg.value were still introduced, despite “-O0” clearly being passed to clang. Did I misinterpret something here and is there any other way to get rid of all calls to llvm.dbg.value in favor of calls to llvm.dbg.declare?