diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3825,7 +3825,8 @@ Flags |= 0x10; Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef{Flags}); - for (const auto &GVI : valueIds()) { + const std::map &ValueIds = valueIds(); + for (const auto &GVI : ValueIds) { Stream.EmitRecord(bitc::FS_VALUE_GUID, ArrayRef{GVI.second, GVI.first}); } @@ -4047,20 +4048,28 @@ if (!Index.cfiFunctionDefs().empty()) { for (auto &S : Index.cfiFunctionDefs()) { - NameVals.push_back(StrtabBuilder.add(S)); - NameVals.push_back(S.size()); + if (ValueIds.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) { + NameVals.push_back(StrtabBuilder.add(S)); + NameVals.push_back(S.size()); + } + } + if (!NameVals.empty()) { + Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals); + NameVals.clear(); } - Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals); - NameVals.clear(); } if (!Index.cfiFunctionDecls().empty()) { for (auto &S : Index.cfiFunctionDecls()) { - NameVals.push_back(StrtabBuilder.add(S)); - NameVals.push_back(S.size()); + if (ValueIds.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) { + NameVals.push_back(StrtabBuilder.add(S)); + NameVals.push_back(S.size()); + } + } + if (!NameVals.empty()) { + Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals); + NameVals.clear(); } - Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals); - NameVals.clear(); } // Walk the GUIDs that were referenced, and write the