]> granicus.if.org Git - clang/commitdiff
Fix PR8419. Reviewed by kremenek and xuzhongxing.
authorZhanyong Wan <wan@google.com>
Mon, 22 Nov 2010 08:45:56 +0000 (08:45 +0000)
committerZhanyong Wan <wan@google.com>
Mon, 22 Nov 2010 08:45:56 +0000 (08:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119960 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
test/Analysis/misc-ps-region-store.cpp

index b58e9826d336c2f8051496d515c2351474afd486..c5ac453d4dd70994c09f726be75f96e8b97ded4a 100644 (file)
@@ -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<SwitchStmt>(S));
 
+    case Stmt::UnaryOperatorClass:
+      return VisitUnaryOperator(cast<UnaryOperator>(S), asc);
+
     case Stmt::WhileStmtClass:
       return VisitWhileStmt(cast<WhileStmt>(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 ||
index dbdfa772a6b9484e49ed09a267541750f64769f7..e87fba41f9687c7e61632c17da169de3178a8333 100644 (file)
@@ -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);