Fix PR2267, by allowing indirect outputs to be intermixed
[oota-llvm.git] / lib / VMCore / InlineAsm.cpp
index e3634e2be539d8e296c09e6e933dff171db936e1..5eefc8842bafb15daf15838d9dd5b944d280b091 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -183,15 +183,18 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &ConstStr) {
   if (Constraints.empty() && !ConstStr.empty()) return false;
   
   unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
+  unsigned NumIndirect = 0;
   
   for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
     switch (Constraints[i].Type) {
     case InlineAsm::isOutput:
+      if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0)
+        return false;  // outputs before inputs and clobbers.
       if (!Constraints[i].isIndirect) {
-        if (NumInputs || NumClobbers) return false;  // outputs come first.
         ++NumOutputs;
         break;
       }
+      ++NumIndirect;
       // FALLTHROUGH for Indirect Outputs.
     case InlineAsm::isInput:
       if (NumClobbers) return false;               // inputs before clobbers.
@@ -202,14 +205,22 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &ConstStr) {
       break;
     }
   }
-    
-  if (NumOutputs > 1) return false;  // Only one result allowed so far.
   
-  if ((Ty->getReturnType() != Type::VoidTy) != NumOutputs)
-    return false;   // NumOutputs = 1 iff has a result type.
+  switch (NumOutputs) {
+  case 0:
+    if (Ty->getReturnType() != Type::VoidTy) return false;
+    break;
+  case 1:
+    if (isa<StructType>(Ty->getReturnType())) return false;
+    break;
+  default:
+    const StructType *STy = dyn_cast<StructType>(Ty->getReturnType());
+    if (STy == 0 || STy->getNumElements() != NumOutputs)
+      return false;
+    break;
+  }      
   
   if (Ty->getNumParams() != NumInputs) return false;
   return true;
 }
 
-DEFINING_FILE_FOR(InlineAsm)