From c63fa612e46ec56776474580c72c7fb761e8777d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 29 Dec 2014 04:09:59 +0000 Subject: Sema: Forbid inconsistent constraint alternatives Verify that asm constraints have the same number of alternatives llvm-svn: 224911 --- clang/lib/Sema/SemaStmtAsm.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'clang/lib') diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index e0f3dfe6e00..b31bb250dd8 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -317,8 +317,28 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, } // Validate tied input operands for type mismatches. + unsigned NumAlternatives = ~0U; + for (unsigned i = 0, e = OutputConstraintInfos.size(); i != e; ++i) { + TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i]; + StringRef ConstraintStr = Info.getConstraintStr(); + unsigned AltCount = ConstraintStr.count(',') + 1; + if (NumAlternatives == ~0U) + NumAlternatives = AltCount; + else if (NumAlternatives != AltCount) + return StmtError(Diag(NS->getOutputExpr(i)->getLocStart(), + diag::err_asm_unexpected_constraint_alternatives) + << NumAlternatives << AltCount); + } for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) { TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; + StringRef ConstraintStr = Info.getConstraintStr(); + unsigned AltCount = ConstraintStr.count(',') + 1; + if (NumAlternatives == ~0U) + NumAlternatives = AltCount; + else if (NumAlternatives != AltCount) + return StmtError(Diag(NS->getInputExpr(i)->getLocStart(), + diag::err_asm_unexpected_constraint_alternatives) + << NumAlternatives << AltCount); // 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 -- cgit v1.2.3