In erroneous inline assembly we could mistakenly try to access the
authorEric Christopher <echristo@apple.com>
Thu, 22 Mar 2012 01:33:51 +0000 (01:33 +0000)
committerEric Christopher <echristo@apple.com>
Thu, 22 Mar 2012 01:33:51 +0000 (01:33 +0000)
metadata operand as an actual operand, leading to an assert. Error
out in this case.

rdar://11007633

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153234 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

index 8eda889155a2ef1a099960513afa4dc2551f29c5..d60585465be038bcec6a7034ee671c8e8c1edfe7 100644 (file)
@@ -326,7 +326,11 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
           OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
         }
 
-        if (OpNo >= MI->getNumOperands()) {
+       // We may have a location metadata attached to the end of the
+       // instruction, and at no point should see metadata at any
+       // other point while processing. It's an error if so.
+        if (OpNo >= MI->getNumOperands() ||
+           MI->getOperand(OpNo).isMetadata()) {
           Error = true;
         } else {
           unsigned OpFlags = MI->getOperand(OpNo).getImm();