For ObjCAtCatchStmt, removed field 'NextAtCatchStmt' (which referenced the next @catch)
and put the the next ObjcAtCatchStmt* as part of SubExprs. This fixes a bug with
iterating over the children of ObjcAtCatch, where the next @catch was not
properly being iterated over as a child.
Altered serialization of ObjCAtCatchStmt to reflect this new layout of
its subexpressions, and fixed an ownership issue with the next @catch not
being serialized as an owned pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46647 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index fd72481..249794d 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -152,13 +152,14 @@
SubExprs[SELECTOR] = catchVarStmtDecl;
SubExprs[BODY] = atCatchStmt;
if (!atCatchList)
- NextAtCatchStmt = NULL;
+ SubExprs[NEXT_CATCH] = NULL;
else {
- ObjCAtCatchStmt *AtCatchList =
- static_cast<ObjCAtCatchStmt*>(atCatchList);
- while (AtCatchList->NextAtCatchStmt)
- AtCatchList = AtCatchList->NextAtCatchStmt;
- AtCatchList->NextAtCatchStmt = this;
+ ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList);
+
+ while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt())
+ AtCatchList = NextCatch;
+
+ AtCatchList->SubExprs[NEXT_CATCH] = this;
}
AtCatchLoc = atCatchLoc;
RParenLoc = rparenloc;
diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp
index 227f365..9a03a53 100644
--- a/AST/StmtSerialization.cpp
+++ b/AST/StmtSerialization.cpp
@@ -859,8 +859,7 @@
void ObjCAtCatchStmt::EmitImpl(Serializer& S) const {
S.Emit(AtCatchLoc);
S.Emit(RParenLoc);
- S.EmitPtr(NextAtCatchStmt);
- S.BatchEmitOwnedPtrs((unsigned) END_EXPR,&SubExprs[0]);
+ S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubExprs[0]);
}
ObjCAtCatchStmt* ObjCAtCatchStmt::CreateImpl(Deserializer& D) {
@@ -868,8 +867,6 @@
SourceLocation RParenLoc = SourceLocation::ReadVal(D);
ObjCAtCatchStmt* stmt = new ObjCAtCatchStmt(AtCatchLoc,RParenLoc);
-
- D.ReadPtr(stmt->NextAtCatchStmt); // Allows backpatching.
D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubExprs[0]);
return stmt;
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 0018c54..751d995 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -817,9 +817,7 @@
/// ObjCAtCatchStmt - This represents objective-c's @catch statement.
class ObjCAtCatchStmt : public Stmt {
private:
- // Points to next @catch statement, or null
- ObjCAtCatchStmt *NextAtCatchStmt;
- enum { SELECTOR, BODY, END_EXPR };
+ enum { SELECTOR, BODY, NEXT_CATCH, END_EXPR };
Stmt *SubExprs[END_EXPR];
SourceLocation AtCatchLoc, RParenLoc;
@@ -833,8 +831,14 @@
const Stmt *getCatchBody() const { return SubExprs[BODY]; }
Stmt *getCatchBody() { return SubExprs[BODY]; }
- const ObjCAtCatchStmt *getNextCatchStmt() const { return NextAtCatchStmt; }
- ObjCAtCatchStmt *getNextCatchStmt() { return NextAtCatchStmt; }
+
+ const ObjCAtCatchStmt *getNextCatchStmt() const {
+ return static_cast<const ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
+ }
+ ObjCAtCatchStmt *getNextCatchStmt() {
+ return static_cast<ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
+ }
+
const Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; }
Stmt *getCatchParamStmt() { return SubExprs[SELECTOR]; }