From: Zhanyong Wan Date: Mon, 22 Nov 2010 08:45:56 +0000 (+0000) Subject: Fix PR8419. Reviewed by kremenek and xuzhongxing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99cae5b67b9711ca260e5b364a878a1a91183632;p=clang Fix PR8419. Reviewed by kremenek and xuzhongxing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119960 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index b58e9826d3..c5ac453d4d 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -296,6 +296,7 @@ private: CFGBlock *VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, AddStmtChoice asc); CFGBlock *VisitStmtExpr(StmtExpr *S, AddStmtChoice asc); CFGBlock *VisitSwitchStmt(SwitchStmt *S); + CFGBlock *VisitUnaryOperator(UnaryOperator *U, AddStmtChoice asc); CFGBlock *VisitWhileStmt(WhileStmt *W); CFGBlock *Visit(Stmt *S, AddStmtChoice asc = AddStmtChoice::NotAlwaysAdd); @@ -886,6 +887,9 @@ tryAgain: case Stmt::SwitchStmtClass: return VisitSwitchStmt(cast(S)); + case Stmt::UnaryOperatorClass: + return VisitUnaryOperator(cast(S), asc); + case Stmt::WhileStmtClass: return VisitWhileStmt(cast(S)); } @@ -922,6 +926,19 @@ CFGBlock *CFGBuilder::VisitAddrLabelExpr(AddrLabelExpr *A, return Block; } +CFGBlock *CFGBuilder::VisitUnaryOperator(UnaryOperator *U, + AddStmtChoice asc) { + if (asc.alwaysAdd()) { + autoCreateBlock(); + AppendStmt(Block, U, asc); + } + + bool asLVal = U->isIncrementDecrementOp(); + return Visit(U->getSubExpr(), + asLVal ? AddStmtChoice::AsLValueNotAlwaysAdd : + AddStmtChoice::NotAlwaysAdd); +} + CFGBlock *CFGBuilder::VisitBinaryOperator(BinaryOperator *B, AddStmtChoice asc) { if (B->isLogicalOp()) { // && or || diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index dbdfa772a6..e87fba41f9 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -159,6 +159,25 @@ int r8375510(R8375510 x, R8375510 y) { for (; ; x++) { } } +// PR8419 -- this used to crash. + +class String8419 { + public: + char& get(int n); + char& operator[](int n); +}; + +char& get8419(); + +void Test8419() { + String8419 s; + ++(s.get(0)); + get8419()--; // used to crash + --s[0]; // used to crash + s[0] &= 1; // used to crash + s[0]++; // used to crash +} + // PR8426 -- this used to crash. void Use(void* to);