[cfe-commits] r66598 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp lib/CodeGen/CGStmt.cpp lib/Sema/SemaStmt.cpp

Chris Lattner sabre at nondot.org
Tue Mar 10 16:41:04 PDT 2009


Author: lattner
Date: Tue Mar 10 18:41:04 2009
New Revision: 66598

URL: http://llvm.org/viewvc/llvm-project?rev=66598&view=rev
Log:
add plumbing to report diagnostics back through sema for malformed asmstrings.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Stmt.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=66598&r1=66597&r2=66598&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Mar 10 18:41:04 2009
@@ -973,8 +973,8 @@
   /// 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 ---===//

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=66598&r1=66597&r2=66598&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Mar 10 18:41:04 2009
@@ -182,8 +182,8 @@
 /// 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();
   

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=66598&r1=66597&r2=66598&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Tue Mar 10 18:41:04 2009
@@ -756,7 +756,8 @@
   // 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;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=66598&r1=66597&r2=66598&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Mar 10 18:41:04 2009
@@ -958,10 +958,24 @@
   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





More information about the cfe-commits mailing list