]> granicus.if.org Git - clang/commitdiff
refactor matched operand type checking to happen after the AsmStmt is created,
authorChris Lattner <sabre@nondot.org>
Sun, 3 May 2009 05:55:43 +0000 (05:55 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 3 May 2009 05:55:43 +0000 (05:55 +0000)
no functionality change.

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

lib/Sema/SemaStmt.cpp

index 243b5695c393ce7ee6971d0596ceb305780337c1..88c7690f86b40849e620ba4eccf5fe730665b7c2 100644 (file)
@@ -951,6 +951,8 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
     OutputConstraintInfos.push_back(Info);
   }
 
+  llvm::SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
+
   for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
     StringLiteral *Literal = Constraints[i];
     if (Literal->isWide())
@@ -989,23 +991,7 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
     
     DefaultFunctionArrayConversion(Exprs[i]);
     
-    // If this is a tied constraint, verify that the output and input have
-    // either exactly the same type, or that they are int/ptr operands with the
-    // same size (int/long, int*/long, are ok etc).
-    if (Info.hasTiedOperand()) {
-      unsigned TiedTo = Info.getTiedOperand();
-      QualType T1 = Exprs[TiedTo]->getType(), T2 = Exprs[i]->getType();
-      if (!Context.hasSameType(T1, T2)) {
-        // Int/ptr operands are ok if they are the same size.
-        if (!(T1->isIntegerType() || T1->isPointerType()) ||
-            !(T2->isIntegerType() || T2->isPointerType()) ||
-            Context.getTypeSize(T1) != Context.getTypeSize(T2))
-          return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
-                                diag::err_asm_tying_incompatible_types)
-                           << T2 << T1 << Exprs[TiedTo]->getSourceRange()
-                           << Exprs[i]->getSourceRange());
-      }
-    }
+    InputConstraintInfos.push_back(Info);
   }
 
   // Check that the clobbers are valid.
@@ -1043,6 +1029,38 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
     return StmtError();
   }
   
+  // Validate tied input operands for type mismatches.
+  for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
+    TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
+    
+    // If this is a tied constraint, verify that the output and input have
+    // either exactly the same type, or that they are int/ptr operands with the
+    // same size (int/long, int*/long, are ok etc).
+    if (!Info.hasTiedOperand()) continue;
+    
+    unsigned TiedTo = Info.getTiedOperand();
+    Expr *OutputExpr     = Exprs[TiedTo];
+    ParenExpr *InputExpr = cast<ParenExpr>(Exprs[i+NumOutputs]);
+    QualType T1 = OutputExpr->getType();
+    QualType T2 = InputExpr->getType();
+    if (Context.hasSameType(T1, T2))
+      continue;  // All types can be tied to themselves.
+    
+    
+    // Int/ptr operands are ok if they are the same size.
+    if ((T1->isIntegerType() || T1->isPointerType()) &&
+        (T2->isIntegerType() || T2->isPointerType())) {
+      if (Context.getTypeSize(T1) == Context.getTypeSize(T2))
+        continue;
+    }
+    
+    Diag(InputExpr->getSubExpr()->getLocStart(),
+         diag::err_asm_tying_incompatible_types)
+      << T2 << T1 << OutputExpr->getSourceRange()
+      << InputExpr->getSourceRange();
+    DeleteStmt(NS);
+    return StmtError();
+  }
   
   return Owned(NS);
 }