diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -143,8 +143,6 @@ auto *GVContext = GV->getScope(); const DIType *GTy = GV->getType(); - // Construct the context before querying for the existence of the DIE in - // case such construction creates the DIE. auto *CB = GVContext ? dyn_cast(GVContext) : nullptr; DIE *ContextDIE = CB ? getOrCreateCommonBlock(CB, GlobalExprs) : getOrCreateContextDIE(GVContext); @@ -351,12 +349,10 @@ DIE *DwarfCompileUnit::getOrCreateCommonBlock( const DICommonBlock *CB, ArrayRef GlobalExprs) { - // Construct the context before querying for the existence of the DIE in case - // such construction creates the DIE. - DIE *ContextDIE = getOrCreateContextDIE(CB->getScope()); - + // Check for pre-existence. if (DIE *NDie = getDIE(CB)) return NDie; + DIE *ContextDIE = getOrCreateContextDIE(CB->getScope()); DIE &NDie = createAndAddDIE(dwarf::DW_TAG_common_block, *ContextDIE, CB); StringRef Name = CB->getName().empty() ? "_BLNK_" : CB->getName(); addString(NDie, dwarf::DW_AT_name, Name);