Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

globalopt removes debug info leaving incomplete metadata #20396

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20397
Status CONFIRMED
Importance P normal
Reported by Razvan Ghitulete (razvan.ghitulete@gmail.com)
Reported on 2014-07-22 04:30:44 -0700
Last modified on 2020-01-16 07:17:42 -0800
Version trunk
Hardware PC Linux
CC anmparal@cisco.com, llvm-bugs@lists.llvm.org, victory@csail.mit.edu
Fixed by commit(s)
Attachments test.c (110 bytes, text/x-csrc)
Blocks
Blocked by
See also

Created attachment 12808 Example source where mmu variable metadata gets stripped after applying globalopt

When using the globalopt optimization (every optimization level except O0) the debug metadata is partially removed, and there is no more reference to the global value inside the associated variable metadata. This interferes with any subsequent passes that might make use of such debug info.

Quuxplusone commented 10 years ago

Attached test.c (110 bytes, text/x-csrc): Example source where mmu variable metadata gets stripped after applying globalopt

Quuxplusone commented 4 years ago

I ran into this same issue on trunk. It seems GlobalOpt makes no efforts to preserve debug info on code that accesses global variables. In particular, in the case that GlobalOpt messes with the type of a global variable in TryToShrinkGlobalToBoolean(), GlobalOpt needs to replace all the loads and stores of the global with new loads and stores of the correct type. So it uses new LoadInst and new StoreInst to generate the new instructions and then erases the old ones, where it should be doing at least something like New->setDebugLoc(Old->getDebugLoc()).

Elsewhere in LLVM, one can usually depend on LLVM transforms preserving at least line information for load and store instructions. This helps a lot with error reporting for sanitizers.