mirror of
https://github.com/RPCSX/llvm.git
synced 2026-01-31 01:05:23 +01:00
Merging r294318:
------------------------------------------------------------------------ r294318 | adrian | 2017-02-07 09:35:41 -0800 (Tue, 07 Feb 2017) | 12 lines Fix the bitcode upgrade for DIGlobalVariable in a DIImportedEntity context. The bitcode upgrade for DIGlobalVariable unconditionally wrapped DIGlobalVariables in a DIGlobalVariableExpression. When a DIGlobalVariable is referenced by a DIImportedEntity, however, this is wrong. This patch fixes the bitcode upgrade by deferring the creation of DIGlobalVariableExpressions until we know the context of the DIGlobalVariable. <rdar://problem/30134279> Differential Revision: https://reviews.llvm.org/D29349 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@294352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -448,6 +448,7 @@ class MetadataLoader::MetadataLoaderImpl {
|
||||
|
||||
bool StripTBAA = false;
|
||||
bool HasSeenOldLoopTags = false;
|
||||
bool NeedUpgradeToDIGlobalVariableExpression = false;
|
||||
|
||||
/// True if metadata is being parsed for a module being ThinLTO imported.
|
||||
bool IsImporting = false;
|
||||
@@ -473,6 +474,45 @@ class MetadataLoader::MetadataLoaderImpl {
|
||||
CUSubprograms.clear();
|
||||
}
|
||||
|
||||
/// Upgrade old-style bare DIGlobalVariables to DIGlobalVariableExpressions.
|
||||
void upgradeCUVariables() {
|
||||
if (!NeedUpgradeToDIGlobalVariableExpression)
|
||||
return;
|
||||
|
||||
// Upgrade list of variables attached to the CUs.
|
||||
if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu"))
|
||||
for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
|
||||
auto *CU = cast<DICompileUnit>(CUNodes->getOperand(I));
|
||||
if (auto *GVs = dyn_cast_or_null<MDTuple>(CU->getRawGlobalVariables()))
|
||||
for (unsigned I = 0; I < GVs->getNumOperands(); I++)
|
||||
if (auto *GV =
|
||||
dyn_cast_or_null<DIGlobalVariable>(GVs->getOperand(I))) {
|
||||
auto *DGVE =
|
||||
DIGlobalVariableExpression::getDistinct(Context, GV, nullptr);
|
||||
GVs->replaceOperandWith(I, DGVE);
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade variables attached to globals.
|
||||
for (auto &GV : TheModule.globals()) {
|
||||
SmallVector<MDNode *, 1> MDs, NewMDs;
|
||||
GV.getMetadata(LLVMContext::MD_dbg, MDs);
|
||||
GV.eraseMetadata(LLVMContext::MD_dbg);
|
||||
for (auto *MD : MDs)
|
||||
if (auto *DGV = dyn_cast_or_null<DIGlobalVariable>(MD)) {
|
||||
auto *DGVE =
|
||||
DIGlobalVariableExpression::getDistinct(Context, DGV, nullptr);
|
||||
GV.addMetadata(LLVMContext::MD_dbg, *DGVE);
|
||||
} else
|
||||
GV.addMetadata(LLVMContext::MD_dbg, *MD);
|
||||
}
|
||||
}
|
||||
|
||||
void upgradeDebugInfo() {
|
||||
upgradeCUSubprograms();
|
||||
upgradeCUVariables();
|
||||
}
|
||||
|
||||
public:
|
||||
MetadataLoaderImpl(BitstreamCursor &Stream, Module &TheModule,
|
||||
BitcodeReaderValueList &ValueList,
|
||||
@@ -726,7 +766,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
|
||||
// Reading the named metadata created forward references and/or
|
||||
// placeholders, that we flush here.
|
||||
resolveForwardRefsAndPlaceholders(Placeholders);
|
||||
upgradeCUSubprograms();
|
||||
upgradeDebugInfo();
|
||||
// Return at the beginning of the block, since it is easy to skip it
|
||||
// entirely from there.
|
||||
Stream.ReadBlockEnd(); // Pop the abbrev block context.
|
||||
@@ -750,7 +790,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
|
||||
return error("Malformed block");
|
||||
case BitstreamEntry::EndBlock:
|
||||
resolveForwardRefsAndPlaceholders(Placeholders);
|
||||
upgradeCUSubprograms();
|
||||
upgradeDebugInfo();
|
||||
return Error::success();
|
||||
case BitstreamEntry::Record:
|
||||
// The interesting case.
|
||||
@@ -1420,11 +1460,17 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
|
||||
getDITypeRefOrNull(Record[6]), Record[7], Record[8],
|
||||
getMDOrNull(Record[10]), AlignInBits));
|
||||
|
||||
auto *DGVE = DIGlobalVariableExpression::getDistinct(Context, DGV, Expr);
|
||||
MetadataList.assignValue(DGVE, NextMetadataNo);
|
||||
NextMetadataNo++;
|
||||
DIGlobalVariableExpression *DGVE = nullptr;
|
||||
if (Attach || Expr)
|
||||
DGVE = DIGlobalVariableExpression::getDistinct(Context, DGV, Expr);
|
||||
else
|
||||
NeedUpgradeToDIGlobalVariableExpression = true;
|
||||
if (Attach)
|
||||
Attach->addDebugInfo(DGVE);
|
||||
|
||||
auto *MDNode = Expr ? cast<Metadata>(DGVE) : cast<Metadata>(DGV);
|
||||
MetadataList.assignValue(MDNode, NextMetadataNo);
|
||||
NextMetadataNo++;
|
||||
} else
|
||||
return error("Invalid record");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user