aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-10 23:41:04 +0000
committerChris Lattner <sabre@nondot.org>2009-03-10 23:41:04 +0000
commitfb5058ef67c054296c88db18ab1b3717845cb71d (patch)
tree28b31a230573ad4b481a6a174b479c81029d4894
parent458cd9c8a79b25b87dcea43c9d97a4c59f194799 (diff)
add plumbing to report diagnostics back through sema for malformed asmstrings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66598 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Stmt.h4
-rw-r--r--lib/AST/Stmt.cpp4
-rw-r--r--lib/CodeGen/CGStmt.cpp3
-rw-r--r--lib/Sema/SemaStmt.cpp22
4 files changed, 24 insertions, 9 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 513c5d9556..d87cee0566 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -973,8 +973,8 @@ public:
/// true, otherwise return false. This handles canonicalization and
/// translation of strings from GCC syntax to LLVM IR syntax, and handles
//// flattening of named references like %[foo] to Operand AsmStringPiece's.
- bool AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces,
- ASTContext &C) const;
+ unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces,
+ ASTContext &C, unsigned &DiagOffs) const;
//===--- Output operands ---===//
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 5335deba33..6b583ee577 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -182,8 +182,8 @@ int AsmStmt::getNamedOperand(const std::string &SymbolicName) const {
/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
/// it into pieces. If the asm string is erroneous, emit errors and return
/// true, otherwise return false.
-bool AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces,
- ASTContext &C) const {
+unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
+ ASTContext &C, unsigned &DiagOffs) const {
const char *StrStart = getAsmString()->getStrData();
const char *StrEnd = StrStart + getAsmString()->getByteLength();
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 26eb039d53..fddc547fd3 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -756,7 +756,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
// Analyze the asm string to decompose it into its pieces. We know that Sema
// has already done this, so it is guaranteed to be successful.
llvm::SmallVector<AsmStmt::AsmStringPiece, 4> Pieces;
- S.AnalyzeAsmString(Pieces, getContext());
+ unsigned DiagOffs;
+ S.AnalyzeAsmString(Pieces, getContext(), DiagOffs);
// Assemble the pieces into the final asm string.
std::string AsmString;
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index fcc501c45d..55f556444d 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -958,10 +958,24 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
exprs.release();
asmString.release();
clobbers.release();
- return Owned(new (Context) AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
- NumInputs, Names, Constraints, Exprs,
- AsmString, NumClobbers,
- Clobbers, RParenLoc));
+ AsmStmt *NS =
+ new (Context) AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
+ Names, Constraints, Exprs, AsmString, NumClobbers,
+ Clobbers, RParenLoc);
+ // Validate the asm string, ensuring it makes sense given the operands we
+ // have.
+ llvm::SmallVector<AsmStmt::AsmStringPiece, 8> Pieces;
+ unsigned DiagOffs;
+ if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
+ // FIXME: get offsets in strings working.
+ // StringLiteralParser::getOffsetOfStringByte
+ Diag(AsmString->getLocStart(), DiagID) << AsmString->getSourceRange();
+ DeleteStmt(NS);
+ return StmtError();
+ }
+
+
+ return Owned(NS);
}
Action::OwningStmtResult