diff options
| author | Anders Carlsson <andersca@mac.com> | 2007-11-27 04:11:28 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2007-11-27 04:11:28 +0000 |
| commit | f511f646a4a392840759e64d66d0d6ffae253287 (patch) | |
| tree | 091520778021726225cfd7c0ce853b48596c9a2c /clang/Sema/SemaStmt.cpp | |
| parent | b0dd27ee91d9d93e3226e6f3a03700e63bb38fe7 (diff) | |
| download | bcm5719-llvm-f511f646a4a392840759e64d66d0d6ffae253287.tar.gz bcm5719-llvm-f511f646a4a392840759e64d66d0d6ffae253287.zip | |
Add more semantic analysis for inline asm statements.
llvm-svn: 44349
Diffstat (limited to 'clang/Sema/SemaStmt.cpp')
| -rw-r--r-- | clang/Sema/SemaStmt.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp index 7f5d038e71e..d051f6b333e 100644 --- a/clang/Sema/SemaStmt.cpp +++ b/clang/Sema/SemaStmt.cpp @@ -659,11 +659,26 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, SourceLocation RParenLoc) { Expr *E = (Expr *)AsmString; - // Check that the output exprs are valid lvalues. for (unsigned i = 0; i < NumOutputs; i++) { + StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]); + assert(!Literal->isWide() && + "Output constraint strings should not be wide!"); + + std::string OutputConstraint(Literal->getStrData(), + Literal->getByteLength()); + + TargetInfo::ConstraintInfo info; + if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(), + info)) { + // FIXME: We currently leak memory here. + Diag(Literal->getLocStart(), + diag::err_invalid_output_constraint_in_asm); + return true; + } + + // Check that the output exprs are valid lvalues. Expr *OutputExpr = (Expr *)Exprs[i]; Expr::isLvalueResult Result = OutputExpr->isLvalue(); - if (Result != Expr::LV_Valid) { ParenExpr *PE = cast<ParenExpr>(OutputExpr); @@ -676,10 +691,26 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, } } - // Check that the input exprs aren't of type void. for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { - Expr *InputExpr = (Expr *)Exprs[i]; + StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]); + assert(!Literal->isWide() && + "Output constraint strings should not be wide!"); + + std::string InputConstraint(Literal->getStrData(), + Literal->getByteLength()); + + TargetInfo::ConstraintInfo info; + if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), + NumOutputs, + info)) { + // FIXME: We currently leak memory here. + Diag(Literal->getLocStart(), + diag::err_invalid_input_constraint_in_asm); + return true; + } + // Check that the input exprs aren't of type void. + Expr *InputExpr = (Expr *)Exprs[i]; if (InputExpr->getType()->isVoidType()) { ParenExpr *PE = cast<ParenExpr>(InputExpr); |

