ASAN transforms global variables into an array with extra storage at the end and RAUWs the global value with a GEP into the array. GlobalOpts will think that the GEP constexpr is dead because its only use is a Metadata node and eliminate it, thus dropping the storage from the debug info.
This patch fixes this by adding a flag to Constant::removeDeadConstantUsers() to optionally ignore metadata users.
Details
- Reviewers
dblaikie rgov samsonov echristo dexonsmith
Diff Detail
Event Timeline
Ugh, this is ugly. We should really start using a !dbg attachment on
global variables, much like we changed functions. Then ASan can update
the attachment (if necessary), and we don't rely on RAUW to get things
right. (I'm not sure that needs to happen before we fix this bug.)
Comments inline.
I added a check to catch the case where the GV is only kept alive by a constant that is only kept alive by metadata.
I'm concerned that fixing up GlobalOpt::deleteIfDead isn't enough
to avoid affecting CodeGen. There are other places in the
pipeline that will check Value::use_empty and/or have logic like
(or use directly) Function::isDefTriviallyDead. I think it's
important that the call to GV.removeDeadConstantUsers() has the
same effect on use-lists whether or not there's any debug info.
Moreover, GlobalOpt::deleteIfDead should have the same effect on
the entire module (including use-lists) regardless of debug info.
(But in case you can convince me, more comments below.)
Alright, I'm not sure if I want to invest any more time in this patch. I will investigate how much work it is to reverse the pointers between CU and global variables next.
Attaching a WIP patch for reversing the ownership between DIGlobalVariable and GlobalVariable.
"Requesting changes" as I assume this at least needs to be rebased, but I still think it's a good direction. Is the a reason this wasn't pursued further?