llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.15k stars 11.62k forks source link

globalopt removes debug info leaving incomplete metadata #20771

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 20397
Version trunk
OS Linux
Attachments Example source where mmu variable metadata gets stripped after applying globalopt
Reporter LLVM Bugzilla Contributor
CC @anmparal,@VictorYing

Extended Description

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.

VictorYing 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.

llvmbot commented 10 years ago

assigned to @anmparal