[inline asm] Add a check in InlineAsm::ConstraintInfo::Parse to make sure '{'
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 5 Sep 2014 22:30:32 +0000 (22:30 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 5 Sep 2014 22:30:32 +0000 (22:30 +0000)
follows '~' in a clobber constraint string.

Previously llc would hit an llvm_unreachable when compiling an inline-asm
instruction with malformed constraint string "~x{21}". This commit enables
LLParser to catch the error earlier and print a more helpful diagnostic.

rdar://problem/14206559

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

lib/IR/InlineAsm.cpp
test/Assembler/inline-asm-clobber.ll [new file with mode: 0644]

index a3e1da3b189ae24154e6cd58f51a58a7a2415a39..16d874f32fc39a76eb684d9a9cfe9e484822f05f 100644 (file)
@@ -91,6 +91,10 @@ bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
   if (*I == '~') {
     Type = isClobber;
     ++I;
+
+    // '{' must immediately follow '~'.
+    if (I != E && *I != '{')
+      return true;
   } else if (*I == '=') {
     ++I;
     Type = isOutput;
diff --git a/test/Assembler/inline-asm-clobber.ll b/test/Assembler/inline-asm-clobber.ll
new file mode 100644 (file)
index 0000000..65c8e44
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: not llvm-as <%s 2>&1  | FileCheck %s
+
+; "~x{21}" is not a valid clobber constraint.
+
+; CHECK: invalid type for inline asm constraint string
+
+define void @foo() nounwind {
+  call void asm sideeffect "mov x0, #42", "~{x0},~{x19},~x{21}"() nounwind
+  ret void
+}