[PATCH] D26105: Allow CaseStmt to be initialized with a SubStmt
Kareem Khazem via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 28 16:16:09 PDT 2016
khazem created this revision.
khazem added reviewers: a.sidorin, xazax.hun, doug.gregor, rsmith.
khazem added subscribers: phosek, cfe-commits, smklein.
The CaseStmt constructor now takes an optional SubStmt argument to initialize its SubExprs field with. This fixes an issue where the ASTImporter was constructing a CaseStmt and not setting its SubStmt member, causing a null pointer access when the SubStmt is accessed in the Stmt::stripLabelLikeStatements() function.
https://reviews.llvm.org/D26105
Files:
include/clang/AST/Stmt.h
lib/AST/ASTImporter.cpp
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -5102,12 +5102,15 @@
Expr *ToRHS = Importer.Import(S->getRHS());
if (!ToRHS && S->getRHS())
return nullptr;
+ Stmt *SubStmt = Importer.Import(S->getSubStmt());
+ if (!SubStmt && S->getSubStmt())
+ return nullptr;
SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc());
SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc());
SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
- return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS,
- ToCaseLoc, ToEllipsisLoc,
- ToColonLoc);
+ return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS, ToCaseLoc,
+ ToEllipsisLoc, ToColonLoc,
+ SubStmt);
}
Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) {
Index: include/clang/AST/Stmt.h
===================================================================
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -693,9 +693,10 @@
// GNU "case 1 ... 4" extension
public:
CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
- SourceLocation ellipsisLoc, SourceLocation colonLoc)
+ SourceLocation ellipsisLoc, SourceLocation colonLoc,
+ Stmt *SubStmt=nullptr)
: SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
- SubExprs[SUBSTMT] = nullptr;
+ SubExprs[SUBSTMT] = SubStmt;
SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
EllipsisLoc = ellipsisLoc;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26105.76268.patch
Type: text/x-patch
Size: 1791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161028/6373db0d/attachment.bin>
More information about the cfe-commits
mailing list