Implement *skeletal* support for representing GNU inline asm stmts in the AST,
resolving a crash on a .i file in PR1750. We now generate 49 errors on the
.i file in that bug.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43433 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index 96acbd1..e8ecd0c 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -189,3 +189,7 @@
else return child_iterator();
}
+// AsmStmt
+Stmt::child_iterator AsmStmt::child_begin() { return child_iterator(); }
+Stmt::child_iterator AsmStmt::child_end() { return child_iterator(); }
+
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index 1a433a6..ac6da06 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -316,6 +316,11 @@
OS << ";\n";
}
+
+void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
+ Indent() << "asm (/*todo*/);\n";
+}
+
//===----------------------------------------------------------------------===//
// Expr printing methods.
//===----------------------------------------------------------------------===//
diff --git a/Parse/ParseStmt.cpp b/Parse/ParseStmt.cpp
index 9df20b4..68781c1 100644
--- a/Parse/ParseStmt.cpp
+++ b/Parse/ParseStmt.cpp
@@ -903,7 +903,7 @@
///
Parser::StmtResult Parser::ParseAsmStatement() {
assert(Tok.is(tok::kw_asm) && "Not an asm stmt");
- ConsumeToken();
+ SourceLocation AsmLoc = ConsumeToken();
DeclSpec DS;
SourceLocation Loc = Tok.getLocation();
@@ -948,10 +948,10 @@
}
}
- MatchRHSPunctuation(tok::r_paren, Loc);
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
- // FIXME: Implement action for asm parsing.
- return false;
+ // FIXME: Pass all the details down to the action.
+ return Actions.ActOnAsmStmt(AsmLoc, RParenLoc);
}
/// ParseAsmOperands - Parse the asm-operands production as used by
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 70d2f55..f553356 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -337,6 +337,9 @@
virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp);
+ virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+ SourceLocation RParenLoc);
+
//===--------------------------------------------------------------------===//
// Expression Parsing Callbacks: SemaExpr.cpp.
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp
index 460b50c..31dc236 100644
--- a/Sema/SemaStmt.cpp
+++ b/Sema/SemaStmt.cpp
@@ -644,3 +644,7 @@
return new ReturnStmt(ReturnLoc, (Expr*)RetValExp);
}
+Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
+ SourceLocation RParenLoc) {
+ return new AsmStmt(AsmLoc, RParenLoc);
+}
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index fe4cf8d..de41b46 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -756,7 +756,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 2ebb387..5f4c0d3 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -660,6 +660,27 @@
virtual child_iterator child_end();
};
+/// AsmStmt - This represents a GNU inline-assembly statement extension.
+///
+class AsmStmt : public Stmt {
+ SourceLocation AsmLoc, RParenLoc;
+ // FIXME: This doesn't capture most of the interesting pieces.
+public:
+ AsmStmt(SourceLocation asmloc, SourceLocation rparenloc)
+ : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc) {}
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(AsmLoc, RParenLoc);
+ }
+
+ static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
+ static bool classof(const AsmStmt *) { return true; }
+
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
+
} // end namespace clang
//===----------------------------------------------------------------------===//
diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def
index c8b8221..469f0a8 100644
--- a/include/clang/AST/StmtNodes.def
+++ b/include/clang/AST/StmtNodes.def
@@ -40,6 +40,9 @@
STMT(15, ReturnStmt , Stmt)
STMT(16, DeclStmt , Stmt)
STMT(17, SwitchCase , Stmt)
+
+// GNU Stmt Extensions
+STMT(18, AsmStmt , Stmt)
LAST_STMT(17)
FIRST_EXPR(31)
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 24b47c6..a237bf3 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -282,6 +282,10 @@
ExprTy *RetValExp) {
return 0;
}
+ virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+ SourceLocation RParenLoc) {
+ return 0;
+ }
//===--------------------------------------------------------------------===//
// Expression Parsing Callbacks.