diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h index a186b05d437f..8cf574c6a138 100644 --- a/llvm/include/llvm/IR/AutoUpgrade.h +++ b/llvm/include/llvm/IR/AutoUpgrade.h @@ -37,6 +37,10 @@ namespace llvm { /// intrinsic function with a call to the specified new function. void UpgradeIntrinsicCall(CallInst *CI, Function *NewFn); + // This upgrades the comment for objc retain release markers in inline asm + // calls + void UpgradeInlineAsmString(std::string *AsmStr); + /// This is an auto-upgrade hook for any old intrinsic function syntaxes /// which need to have both the function updated as well as all calls updated /// to the new function. This should only be run in a post-processing fashion diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1a65cee0bf9d..9d826aaac659 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2522,6 +2522,7 @@ Error BitcodeReader::parseConstants() { for (unsigned i = 0; i != ConstStrSize; ++i) ConstrStr += (char)Record[3+AsmStrSize+i]; PointerType *PTy = cast(CurTy); + UpgradeInlineAsmString(&AsmStr); V = InlineAsm::get(cast(PTy->getElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack); break; @@ -2547,6 +2548,7 @@ Error BitcodeReader::parseConstants() { for (unsigned i = 0; i != ConstStrSize; ++i) ConstrStr += (char)Record[3+AsmStrSize+i]; PointerType *PTy = cast(CurTy); + UpgradeInlineAsmString(&AsmStr); V = InlineAsm::get(cast(PTy->getElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack, InlineAsm::AsmDialect(AsmDialect)); diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 78385ac82d3d..f3193f5893cd 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -1169,6 +1169,19 @@ static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder, return true; } +/// Upgrade comment in call to inline asm that represents an objc retain release +/// marker. +void llvm::UpgradeInlineAsmString(std::string *AsmStr) { + + unsigned long Pos; + if (AsmStr->find("mov\tfp") == 0 && + AsmStr->find("objc_retainAutoreleaseReturnValue") != std::string::npos && + (Pos = AsmStr->find("# marker")) != std::string::npos) { + AsmStr->replace(Pos, 1, ";"); + } + return; +} + /// Upgrade a call to an old intrinsic. All argument and return casting must be /// provided to seamlessly integrate with existing context. void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { diff --git a/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll new file mode 100644 index 000000000000..e6a99dde72e0 --- /dev/null +++ b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll @@ -0,0 +1,9 @@ +; Test that comment token for objc retain release is upgraded from '#' to ';' +; +; RUN: llvm-dis < %s.bc | FileCheck %s + +define void @inlineasm() { + call void asm sideeffect "mov\09fp, fp\09\09# marker for objc_retainAutoreleaseReturnValue", ""() + ;CHECK: call void asm sideeffect "mov\09fp, fp\09\09; marker for objc_retainAutoreleaseReturnValue", ""() + ret void +} diff --git a/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc new file mode 100644 index 000000000000..eb9986b8a4d4 Binary files /dev/null and b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc differ