diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-10-25 00:05:55 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-10-25 00:05:55 +0000 |
commit | 753c8782dfeb96609634adb5950929e3b12da3ae (patch) | |
tree | 3b4dc72c9b96d17ceb94355e7b5a691a2a51a29a /clang/lib | |
parent | 9004798da8e158c5b6f3c4110c81e1b27825a4de (diff) | |
download | bcm5719-llvm-753c8782dfeb96609634adb5950929e3b12da3ae.tar.gz bcm5719-llvm-753c8782dfeb96609634adb5950929e3b12da3ae.zip |
Add some support for diagnosing possibly mismatched constraint, type size and
modifiers. (From an idea by Eric...)
<rdar://problem/12284092>
llvm-svn: 166647
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 23 | ||||
-rw-r--r-- | clang/lib/Sema/SemaStmtAsm.cpp | 48 |
2 files changed, 71 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ba96185f72d..960a2858e41 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -3315,6 +3315,29 @@ public: } return R; } + virtual bool validateConstraintModifier(StringRef Constraint, + const char Modifier, + unsigned Size) const { + // Strip off constraint modifiers. + while (Constraint[0] == '=' || + Constraint[0] == '+' || + Constraint[0] == '&') + Constraint = Constraint.substr(1); + + switch (Constraint[0]) { + default: break; + case 'r': { + switch (Modifier) { + default: return Size == 32; + case 'q': + // A register of size 32 cannot fit a vector type. + return false; + } + } + } + + return true; + } virtual const char *getClobbers() const { // FIXME: Is this really right? return ""; diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index 3a5f40c74fa..138d6714701 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -208,6 +208,54 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, return StmtError(); } + // Validate constraints and modifiers. + for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { + GCCAsmStmt::AsmStringPiece &Piece = Pieces[i]; + if (!Piece.isOperand()) continue; + + // Look for the correct constraint index. + unsigned Idx = 0; + unsigned ConstraintIdx = 0; + for (unsigned i = 0, e = NS->getNumOutputs(); i != e; ++i, ++ConstraintIdx) { + TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i]; + if (Idx == Piece.getOperandNo()) + break; + ++Idx; + + if (Info.isReadWrite()) { + if (Idx == Piece.getOperandNo()) + break; + ++Idx; + } + } + + for (unsigned i = 0, e = NS->getNumInputs(); i != e; ++i, ++ConstraintIdx) { + TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; + if (Idx == Piece.getOperandNo()) + break; + ++Idx; + + if (Info.isReadWrite()) { + if (Idx == Piece.getOperandNo()) + break; + ++Idx; + } + } + + // Now that we have the right indexes go ahead and check. + StringLiteral *Literal = Constraints[ConstraintIdx]; + const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr(); + if (Ty->isDependentType() || Ty->isIncompleteType()) + continue; + + unsigned Size = Context.getTypeSize(Ty); + if (!Context.getTargetInfo() + .validateConstraintModifier(Literal->getString(), + Piece.getModifier(), Size)) + Diag(Exprs[ConstraintIdx]->getLocStart(), + diag::warn_mismatched_size_modifier); + } + // Validate tied input operands for type mismatches. for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) { TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; |