aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 66ecc69..290d873 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -293,10 +293,18 @@ static Expected<bool> hasObjCCategoryInModule(BitstreamCursor &Stream) {
std::string S;
if (convertToString(Record, 0, S))
return error("Invalid section name record");
+
// Check for the i386 and other (x86_64, ARM) conventions
- if (S.find("__DATA,__objc_catlist") != std::string::npos ||
- S.find("__OBJC,__category") != std::string::npos ||
- S.find("__TEXT,__swift") != std::string::npos)
+
+ auto [Segment, Section] = StringRef(S).split(",");
+ Segment = Segment.trim();
+ Section = Section.trim();
+
+ if (Segment == "__DATA" && Section.starts_with("__objc_catlist"))
+ return true;
+ if (Segment == "__OBJC" && Section.starts_with("__category"))
+ return true;
+ if (Segment == "__TEXT" && Section.starts_with("__swift"))
return true;
break;
}
@@ -7007,13 +7015,6 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
if (StripDebugInfo)
stripDebugInfo(*F);
- // Upgrade any old intrinsic calls in the function.
- for (auto &I : UpgradedIntrinsics) {
- for (User *U : llvm::make_early_inc_range(I.first->materialized_users()))
- if (CallInst *CI = dyn_cast<CallInst>(U))
- UpgradeIntrinsicCall(CI, I.second);
- }
-
// Finish fn->subprogram upgrade for materialized functions.
if (DISubprogram *SP = MDLoader->lookupSubprogramForFunction(F))
F->setSubprogram(SP);
@@ -7029,7 +7030,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
}
}
- for (auto &I : instructions(F)) {
+ for (auto &I : make_early_inc_range(instructions(F))) {
// "Upgrade" older incorrect branch weights by dropping them.
if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) {
if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) {
@@ -7060,8 +7061,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
}
}
- // Remove incompatible attributes on function calls.
if (auto *CI = dyn_cast<CallBase>(&I)) {
+ // Remove incompatible attributes on function calls.
CI->removeRetAttrs(AttributeFuncs::typeIncompatible(
CI->getFunctionType()->getReturnType(), CI->getRetAttributes()));
@@ -7069,6 +7070,13 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
CI->removeParamAttrs(ArgNo, AttributeFuncs::typeIncompatible(
CI->getArgOperand(ArgNo)->getType(),
CI->getParamAttributes(ArgNo)));
+
+ // Upgrade intrinsics.
+ if (Function *OldFn = CI->getCalledFunction()) {
+ auto It = UpgradedIntrinsics.find(OldFn);
+ if (It != UpgradedIntrinsics.end())
+ UpgradeIntrinsicCall(CI, It->second);
+ }
}
}
@@ -7116,9 +7124,11 @@ Error BitcodeReader::materializeModule() {
if (CallInst *CI = dyn_cast<CallInst>(U))
UpgradeIntrinsicCall(CI, I.second);
}
- if (!I.first->use_empty())
- I.first->replaceAllUsesWith(I.second);
- I.first->eraseFromParent();
+ if (I.first != I.second) {
+ if (!I.first->use_empty())
+ I.first->replaceAllUsesWith(I.second);
+ I.first->eraseFromParent();
+ }
}
UpgradedIntrinsics.clear();